Search code examples
androidnotificationsandroid-remoteview

Transparent notification background in Android


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.


Solution

  • 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