Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the default notification background color for custom notification in Lollipop?

I'm having an issue with the color of my custom notification background in Lollipop. It's black where it should be white. The textColor is OK:

I'm using

<resources>
    <style name="NotificationText" parent="android:TextAppearance.StatusBar.EventContent" />
    <style name="NotificationTitle" parent="android:TextAppearance.StatusBar.EventContent.Title" />
</resources>

Any idea how to use the device default theme color for custom notification ?

like image 617
user1026605 Avatar asked Nov 16 '14 17:11

user1026605


People also ask

How do I change the background color on my notifications?

call setColor -> the color to be used on the background. call setColorized -> the actual call to set the background color. set style to NotificationCompat. DecoratedMediaCustomViewStyle()

How to change the background color of a notification?

Changing background colour of a notification is possible with the version Oreo. It is used with the method ‘setColorized (Boolean)’. This flag is false by default.

How to add custom notification layout in Android Studio?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to res/layout/custom_notification_layout.xml.

Can the notification icon in the status bar have a colour?

monochrome: a photograph or picture developed or executed in black and white or in varying tones of only one colour. The material.io page states that the icon of the notification in the status bar cannot have a colour. You have just 2 options; Have a look at this nice q/a. What about ‘setSmallIcon’?

Should I use the standard notification template for Android?

To ensure your notification looks its best across different versions of Android, you should always use the standard notification template to build your notification. However, if the system templates do not meet your needs, you can provide your own layout for the notification.


1 Answers

Your app's targetSdkVersion must be 21.
As Ahmed's answere, add another styles file in values-21 folder.

<?xml version="1.0" encoding="UTF-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
   <style name="NotificationText" parent="android:TextAppearance.Material.Notification" />
   <style name="NotificationTitle" parent="android:TextAppearance.Material.Notification.Title" />
   <style name="NotificationTime" parent="android:TextAppearance.Material.Notification.Time" />
</resources>    
like image 52
conanoc Avatar answered Sep 18 '22 14:09

conanoc