我尝试为底部导航栏着色
在某些 Android 版本中,它看起来是白色背景和白色图标
protected void updateNavigationBarColor(Window window, boolean isLight) {
if (window == null) {
return;
}
View decorView = window.getDecorView();
if (decorView == null) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
window.setNavigationBarColor(Utils.getColor(R.color.navigation_bar_color));//black or white
WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(window, decorView);
controller.setAppearanceLightNavigationBars(isLight);
} else {
// Do nothing
}
}
导航栏背景颜色正是我所要求的。但 3 个按钮(图标)始终保持亮灯状态
在themes.xml中添加到我的主题
<item name="android:navigationBarColor">@color/transparent</item>
<item name="android:windowLightNavigationBar">true</item>
这是我的编程解决方案,用于将导航栏按钮的颜色更改为深色或浅色背景。
public static void setNavBarForeground(boolean light, Activity activity, View view){
try {
if (!light) {//make buttons dark to be more visible
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
WindowInsetsController windowInsetController = activity.getWindow().getInsetsController();
if (windowInsetController != null)
windowInsetController.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
}
} else { //make buttons light to be more visible
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
WindowInsetsController windowInsetController = activity.getWindow().getInsetsController();
if (windowInsetController != null)
windowInsetController.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
view.setSystemUiVisibility(0);
}
}
}
catch (Exception e){
Logger.log(e);
}
}