Gui*_*lhE 107 android android-styles android-5.0-lollipop android-statusbar
我想知道是否可以更改状态栏图标颜色(而不是状态栏颜色colorPrimaryDark
)
假设我想要这个状态栏:
<item name="colorPrimaryDark">@android:color/white</item>
和黑色的图标,这可能吗?
谢谢.
编辑:
M开发人员预览中的新功能:windowLightStatusBar.在主题中翻转它会告诉系统使用深色前景,对浅色状态栏很有用.请注意,M预览似乎有一个错误,通知图标保持白色,而系统状态图标正确地变为半透明黑色.
来自:Roman Nurik的 Google+ 帖子
eOn*_*nOe 172
是的,可以将其更改为灰色(没有自定义颜色),但这仅适用于API 23及更高版本,您只需在值-v23/styles.xml中添加它
<item name="android:windowLightStatusBar">true</item>
Run Code Online (Sandbox Code Playgroud)
yww*_*ynm 82
@eOnOe回答了我们如何通过xml更改状态栏色调.但我们也可以在代码中动态更改它:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
View decor = getWindow().getDecorView();
if (shouldChangeStatusBarTintToDark) {
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
// We want to change tint color to white again.
// You can also record the flags in advance so that you can turn UI back completely if
// you have set other flags before, such as translucent or full screen.
decor.setSystemUiVisibility(0);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 43
如果您的API级别小于23,则必须以这种方式使用它.它适用于我在v21/style下声明.
<item name="colorPrimaryDark" tools:targetApi="23">@color/colorPrimary</item>
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
Run Code Online (Sandbox Code Playgroud)
Kub*_*tny 22
不是自从棒棒糖.从Android 5.0开始,指南说:
通知图标必须完全为白色.
即使它们不是,系统也只会考虑图标的alpha通道,将它们呈现为白色
在Lollipop上设置彩色图标的唯一方法是降低您targetSdkVersion
的值<21
,但我认为您最好遵循指南并仅使用白色图标.
但是,如果仍然决定要使用彩色图标,则可以使用新v4支持库中的DrawableCompat.setTint方法.
Mar*_*rew 14
SystemUiVisibility标志已弃用。使用WindowInsetsController代替
下面的代码将图标的颜色设置为黑色(对于灯光状态栏)
//icon color -> black
activity.getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS);
Run Code Online (Sandbox Code Playgroud)
下面的代码将其清除(即将图标颜色变为白色以表示深色状态栏):
//icon color -> white
activity.getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS);
Run Code Online (Sandbox Code Playgroud)
您可以通过保留所有其他系统 UI 可见性标志以编程方式完成此操作。
public static void changeStatusBarContrastStyle(Window window, Boolean lightIcons) {
View decorView = window.getDecorView();
if (lightIcons) {
// Draw light icons on a dark background color
decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
// Draw dark icons on a light background color
decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
86186 次 |
最近记录: |