答案 0 :(得分:66)
要使状态栏图标具有深色调而不是默认白色,请在styles.xml
(或更精确地在values-v23/styles.xml
)文件中添加以下标记:
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
您还可以通过将标志设置为任何View
来更改标志:
View yourView = findViewById(R.id.your_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (yourView != null) {
yourView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
如果要重置更改,请清除以下标志:
yourView.setSystemUiVisibility(0);
答案 1 :(得分:1)
下面是示例代码,在纵向和景观之间切换时更改状态栏颜色。肖像模式:灯条,暗图标;横向模式:暗条,浅色图标;主题:&#34; Theme.AppCompat.Light&#34;
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Window window = getWindow();
View decorView = window.getDecorView();
if(Configuration.ORIENTATION_LANDSCAPE == newConfig.orientation) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(Color.parseColor("#55000000")); // set dark color, the icon will auto change light
}
} else {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(Color.parseColor("#fffafafa"));
}
}
}