简体   繁体   中英

Status bar color changing in Android

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>

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

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.

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