Android导航栏图标颜色

问题描述 投票:0回答:2

我尝试为底部导航栏着色
在某些 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 个按钮(图标)始终保持亮灯状态

android navigation uinavigationbar
2个回答
1
投票

在themes.xml中添加到我的主题

<item name="android:navigationBarColor">@color/transparent</item>
<item name="android:windowLightNavigationBar">true</item>

0
投票

这是我的编程解决方案,用于将导航栏按钮的颜色更改为深色或浅色背景。

    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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.