[英]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
:我试图通过更改themes.xml
的这一行来更改其颜色:
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
You should use <item name="android:windowLightStatusBar">true</item>
in your same theme.您应该在同一主题中使用<item name="android:windowLightStatusBar">true</item>
。 It requires at least API 23.它至少需要 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:要在 API 21 上将状态栏颜色更改为白色,通知图标颜色更改为黑色或其他颜色,您可以使用以下方法:
In your styles.xml file, set the color of the status bar to white using the following line:在您的 styles.xml 文件中,使用以下行将状态栏的颜色设置为白色:
<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 class 的 setColor() 方法。例如:
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:要更改 API 21 及以上版本的通知图标颜色,可以使用 NotificationCompat.Builder class 的 setColorized() 方法。例如:
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.这应该将状态栏的颜色更改为白色,将通知图标更改为黑色或 API 21 上的其他颜色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.