Question:
How can I show a coloured application name in an Android push notification?
Answer:
The application name row of a notification is drawn by the system and cannot be recoloured directly. To control it you have to render your own notification layout via a custom Notification Factory:
-
Set the notification accent colour first. On modern Android the app name and the small icon are tinted with the notification accent colour, so in many cases you do not need a custom layout at all - just set the colour in your Pushwoosh notification configuration (
iconBackgroundColor/NotificationServiceExtension) or per-message from the Control Panel. -
If you need full control, create your own Notification Factory. Subclass Pushwoosh's notification factory and register it in your app - see the Android SDK documentation and the sample app in the pushwoosh-android-sdk repository (
Sources/demoapp). -
Create a custom layout (a
RemoteViewsXML layout). In theTextViewthat renders your application name, add the android:textColor attribute with the value you need in the form"#rgb","#argb","#rrggbb"or"#aarrggbb". -
Apply the layout to the notification you build in your factory with NotificationCompat.Builder.setCustomContentView() (AndroidX; the old
android.support.v4package is deprecated).
Caveat: since Android 12 the system applies its own decoration to custom notification content, and OEM skins (Samsung One UI, MIUI/HyperOS, EMUI, ColorOS...) may override styling, so always verify the result on your real target devices.
Comments
0 comments
Please sign in to leave a comment.