0

I want to create Android notification with transparent background. I'm using bigContent with remoteViews to create my own layout, but when i set background color of main layout to @android/color/transparent nothing happens. I still see standard white background of notification.

How can I set transparent background on Android notification? I note that i don't mean notification bar (or status bar) but background of custom notification.

  • Are you sure that the "standard white background" is not coming from the notification tray itself? – CommonsWare Jul 26 '15 at 17:46
  • Yes, I'm sure ;) I create remoteViews with transparent background xml layout but notification looks like it's 'something' behind my layout and I don't how to change color of this 'something' :D – Michał Kuchtar Jul 26 '15 at 17:51
  • "Yes, I'm sure" -- how did you determine this? Unless you are writing your own custom ROM and are limiting your app to that custom ROM, you do not control the behavior of the notification tray. It is up to the ROM developer (usually a device manufacturer) what the notification tray looks and works like. – CommonsWare Jul 26 '15 at 17:55
  • I think that we didn't understand each other. With remoteViews I can create custom notification layout. And in this layout i want to set transparent background. But when I run my app, that notification has not transparent background but still white background. – Michał Kuchtar Jul 26 '15 at 18:03
  • "And in this layout i want to set transparent background" -- you do not control what is behind your `RemoteViews`. It is certainly possible that whatever is behind your `RemoteViews` will be white, such as the background of the notification tray. You claim that you are sure that the notification tray is not the source of the white color. How have you determined this? Or, to put it another way, if not white, what are you expecting to see? – CommonsWare Jul 26 '15 at 18:16
  • Please look at the image: [Some Chinese App](http://picpaste.com/pics/screeen-XRp2JbXp.1437935192.png) First notification has transparent background. Second has standard background. My question is how can I set background in my notification like in first notification from picture? – Michał Kuchtar Jul 26 '15 at 18:28
  • 1
    "First notification has transparent background" -- if you mean what looks like four days of weather forecasts, I do not know if that is a `Notification` or a feature of that device's notification tray. You would need to install that app on some device of yours, see if that four-day forecast shows up in the notification tray, and then see if the background is white. If the four-day forecast does not show up, then your screenshot is only showing one `Notification`. If it shows up but has a white background, that's probably your device's notification tray background. – CommonsWare Jul 26 '15 at 18:33
  • So in Android... Can I set my notification background same like notificaiton tray background or not ;)? To show for example only texts without frame? So it will look similary like this 4-days forecasts? – Michał Kuchtar Jul 26 '15 at 18:36
  • AFAIK, you already are, to the best of your ability. On your device, perhaps it happens to be white. Or, perhaps your particular device puts its own background on individual tiles that is white. Or, perhaps your particular device puts its own background behind expanded notifications ("bigContent") that is white. There is no guarantee of what will be behind your `RemoteViews`, let alone what general color scheme it will be. That is up to whoever built the ROM (device manufacturer, ROM modder, etc.). – CommonsWare Jul 26 '15 at 18:40
  • https://stackoverflow.com/questions/29311078/android-completely-transparent-status-bar If you're still looking, this is possibly your answer. – ShadowRz Aug 24 '19 at 06:58
  • https://stackoverflow.com/questions/29311078/android-completely-transparent-status-bar If you're still looking this is probably your answer. – ShadowRz Aug 24 '19 at 06:59

1 Answers1

2

As CommonsWare is saying in the comments, it's not possible to do this.

Unless changed by a phone manufacturer (which very likely is not allowed) a notification is built in layers. The bottom layer is the background view, it has a grayish color on lollipop (don't remember pre lollipop of the top of my mind) on top of the background view you have the content view supplied by the notification (the view you can make). When you make your view transparent you show the background. You can't change the background.

On lollipop these are the default values:

<color name="notification_legacy_background_color">#ff1a1a1a</color>

<!-- The color of the material notification background -->
<color name="notification_material_background_color">#fffafafa</color>

<!-- The color of the material notification background when dimmed -->
<color name="notification_material_background_dimmed_color">#d4ffffff</color>

 <!-- The color of the material notification background when low priority -->
<color name="notification_material_background_low_priority_color">#ffe0e0e0</color>

<!-- The color of the material notification background for media notifications when no custom
     color is specified -->
<color name="notification_material_background_media_default_color">#ff424242</color>

More information: http://androidxref.com/5.1.1_r6/xref/frameworks/base/packages/SystemUI/res/values/colors.xml#80

http://androidxref.com/5.1.1_r6/xref/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java

JohanShogun
  • 2,956
  • 21
  • 30
  • 2
    "Unless changed by a phone manufacturer (which very likely is not allowed)" -- outside of Nexus-series devices, any other major-manufacturer device usually changes the look and feel of the notification tray from what is in AOSP. And, I do not see anything in the Compatibility Definition Document that would preclude this. – CommonsWare Jul 26 '15 at 18:43
  • Thanks. Now I know that i can't do this ;) – Michał Kuchtar Jul 26 '15 at 18:46
  • You're right CommonsWare, just read the compatibility doc, there is nothing there saying you can't customize the experience. – JohanShogun Jul 26 '15 at 18:48