如何更改前景导航栏颜色?

5

在我的Android应用程序中,我想通过Java编程将导航栏的前景从默认的白色更改为任何其他颜色。例如 -

enter image description here

enter image description here

我已经搜索了Stack Overflow、网络和Android开发者网站。有很多关于如何更改背景的帖子。
getWindow().setNavigationBarColor(mColor);

但是我不知道如何改变前景色。非常感谢您的帮助。

1
你有验证过这是否可能吗?我从未见过这样的情况。 - undefined
我以前没见过这个,只是假设你可以将背景颜色改为白色,那么至少应该能够将前景色切换为黑色吧。这可行吗?我想我实际上并不需要除了白色或黑色之外的颜色。 - undefined
我不认为这是可能的,你可以隐藏系统栏并创建一个自定义导航栏,使用任何你想要的颜色。 - undefined
好的,谢谢。要创建一个新的,我只需要将它插入到我的布局中吗?还是有一个特定的类用于此目的? - undefined
1个回答

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);
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接