2

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:

enter image description here

When Status Bar is non white:

enter image description here

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.

tofa
  • 59
  • 1
  • 8

3 Answers3

0

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.

Ümañg ßürmån
  • 9,695
  • 4
  • 24
  • 41
  • Okay can you post your drawable please – Ümañg ßürmån Aug 24 '18 at 16:09
  • Not working. java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window android.app.Activity.getWindow()' on a null object reference at com.example.myapp.service.DataService.onCreate(DataService.java:121). Actually I want to change status bar icon color only status bar background become white – tofa Aug 24 '18 at 16:10
  • drawable is a long file. I added a portion. – tofa Aug 24 '18 at 16:16
0

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

add the following line of code..

setTheme(R.style.AppTheme);
amit
  • 709
  • 6
  • 17
0

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.

Kaveri
  • 1,060
  • 2
  • 12
  • 21