简体   繁体   English

Android 状态栏颜色变化

[英]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.

相关问题 更改状态栏背景和文字颜色 Android WebView - Changing status bar background and text color in Android WebView 如何更改 Android 中状态栏图标的颜色? - How to change status bar icons color in Android? Android:在工具栏中更改后退按钮的颜色 - Android: Changing color of the back button in tool bar Android更改工具栏颜色和状态栏颜色,但保持状态栏阴影 - Android change toolbar color and status bar color but keep statusbar shadow 状态栏中的通知图标在少数 android 设备中没有变化 - Notification Icon in status bar is not changing in few android devices 如何在所有活动中一起更改Android状态栏颜色 - How to change Android status bar color in all activities together 如何在Codenameone Android应用程序中更改状态栏的颜色? - How to change the color of the status bar in a codenameone android app? Android通知图标可根据状态栏颜色更改背景 - Android notification icon to change background according to status bar color 如何更改 Android Java 上导航栏和状态栏的颜色? - How to change the color of the navigation and status bar on Android Java? 如何在Android中将片段页面中的状态栏颜色更改为透明 - How to change a status bar color in a Fragment page as Transparent in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM