Window window = MainActivity.this.getWindow();
window.setStatusBarColor(MY_COLOR_IT_CAN_BE_ANY);
if (Build.VERSION.SDK_INT < 30)
{
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
else {
window.setDecorFitsSystemWindows(false);
WindowInsetsController controller = getWindow().getInsetsController();
if(controller != null) {
controller.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
}
}
我正在使用此代码在 android 11 及以下 android 11 中设置灯光状态栏。一切正常,只是有点问题,不推荐使用警告。