简体   繁体   中英

Status Bar Icon color does not change with Theme

In Notification, I used drawable xml as a setSmallIcon . When Status Bar background changes to white then my white icon disappears (actually background color and icon become same color). But if I use image icon as a setSmallIcon then status bar icon's color changes to grey.

When Status Bar is white:

在此处输入图片说明

When Status Bar is non white:

在此处输入图片说明

Code:

builder.setSmallIcon(R.drawable.my_list,level); 

A portion of drawable file:

<item android:maxLevel="86">
    <layer-list>
        <item
            android:bottom="@dimen/bottom_margin"
            android:drawable="@drawable/ic_8"
            android:left="@dimen/ic_2_1_left"
            android:right="@dimen/ic_2_1_right"
            android:top="@dimen/upper_margin" />
        <item
            android:bottom="@dimen/bottom_margin"
            android:drawable="@drawable/ic_6"
            android:left="@dimen/ic_2_2_left"
            android:right="@dimen/ic_2_2_right"
            android:top="@dimen/upper_margin" />
    </layer-list>
</item>
<item android:maxLevel="87">
    <layer-list>
        <item
            android:bottom="@dimen/bottom_margin"
            android:drawable="@drawable/ic_8"
            android:left="@dimen/ic_2_1_left"
            android:right="@dimen/ic_2_1_right"
            android:top="@dimen/upper_margin" />
        <item
            android:bottom="@dimen/bottom_margin"
            android:drawable="@drawable/ic_7"
            android:left="@dimen/ic_2_2_left"
            android:right="@dimen/ic_2_2_right"
            android:top="@dimen/upper_margin" />
    </layer-list>
</item>
<item android:maxLevel="88">
    <layer-list>
        <item
            android:bottom="@dimen/bottom_margin"
            android:drawable="@drawable/ic_8"
            android:left="@dimen/ic_2_1_left"
            android:right="@dimen/ic_2_1_right"
            android:top="@dimen/upper_margin" />
        <item
            android:bottom="@dimen/bottom_margin"
            android:drawable="@drawable/ic_8"
            android:left="@dimen/ic_2_2_left"
            android:right="@dimen/ic_2_2_right"
            android:top="@dimen/upper_margin" />
    </layer-list>
</item>

How can I change xml drawable icon color with status bar background(white)?

Sorry for my bad english.

before the super.OnCreate() in your activity....

add the following line of code..

setTheme(R.style.AppTheme);

Try this:

After setting your drawable in your Activity write:

getWindow().setStatusBarColor(Color.parseColor(your_color_in_hex));

See if it works and update please.

Starting with Android 5.0, the guidelines say:

Notification icons must be white.

Even if they're not, the system will only consider the alpha channel of your icon, rendering them white.

Some usefull links :-

Android statusbar icons color

Notification bar icon turns white in Android 5 Lollipop

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM