Home > Back-end >  Status bar color changing
Status bar color changing

Time:01-20

When I change status bar color to white, it makes notification invisible as they are also in white color. How can I change color to white of status bar and changing the notification icons to black or other color?

I tried to change its color by changing this line from themes.xml:

<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>

CodePudding user response:

You should use <item name="android:windowLightStatusBar">true</item> in your same theme. It requires at least API 23.

CodePudding user response:

To change the color of the status bar to white and the notification icons to black or another color on API 21, you can use the following method:

In your styles.xml file, set the color of the status bar to white using the following line:

<item name="android:statusBarColor">#FFFFFF</item>

To change the color of the notification icons, you can use the setColor() method of the NotificationCompat.Builder class. For example:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.icon)
                .setContentTitle("Title")
                .setContentText("Content")
                .setColor(Color.BLACK);

To change the color of the notification icons for API 21 and above, you can use the setColorized() method of the NotificationCompat.Builder class. For example:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.icon)
                .setContentTitle("Title")
                .setContentText("Content")
                .setColorized(true)
                .setColor(Color.BLACK);

This should change the color of the status bar to white and the notification icons to black or another color on API 21.

  • Related