问题描述
我正在更改片段/活动之间的状态栏颜色和文本。对于黑色状态栏,我需要白色文本,反之亦然。由于 Android 11 上的 api 弃用,我正在使用它:
带有浅色文本的深色状态栏:
Window window = getwindow();
if (mDefaultStatusBarColor == null) {
mDefaultStatusBarColor = window.getStatusBarColor();
}
window.setStatusBarColor(ContextCompat.getColor(this,R.color.black));
// Sets status text light
View decorView = window.getDecorView();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsController wic = decorView.getwindowInsetsController();
wic.setSystemBarsAppearance(0,APPEaraNCE_LIGHT_STATUS_BARS);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
decorView.setsystemUIVisibility(decorView.getsystemUIVisibility() & ~View.SYstem_UI_FLAG_LIGHT_STATUS_BAR);
}
更改为带有深色文本的浅色状态栏:
Window window = getwindow();
// Giving the status bar its default color.
if (mDefaultStatusBarColor != null) {
window.setStatusBarColor(mDefaultStatusBarColor);
}
// Sets status text dark
View decorView = window.getDecorView();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsController wic = decorView.getwindowInsetsController();
wic.setSystemBarsAppearance(APPEaraNCE_LIGHT_STATUS_BARS,APPEaraNCE_LIGHT_STATUS_BARS);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
decorView.setsystemUIVisibility(View.SYstem_UI_FLAG_LIGHT_STATUS_BAR);
}
但是第一种情况(带有浅色文本的深色状态栏)无法正常工作,因为文本仍然是深色的。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)