android - 导航栏按钮颜色

标签 android layout uinavigationbar galaxy

我想改变 的颜色导航按钮 在我的应用程序中,
enter image description here

我试过 window.setNavigationBarColor(@ColorInt int color)但这种方法只改变酒吧的背景。有任何想法吗?

最佳答案

您可以使用以下函数动态更改导航颜色。基本上它检查给定的 NavigationBar 背景颜色是浅色还是深色,并为按钮设置适当的主题。无法为按钮设置特定颜色。

private void setNavigationBarButtonsColor(Activity activity, int navigationBarColor) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        View decorView = activity.getWindow().getDecorView();
        int flags = decorView.getSystemUiVisibility();
        if (isColorLight(navigationBarColor)) {
            flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
        } else {
            flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
        }
        decorView.setSystemUiVisibility(flags);
    }
}

private boolean isColorLight(int color) {
    double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
    return darkness < 0.5;
}

关于android - 导航栏按钮颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44905749/

相关文章:

java - 当以 ListView 显示个人资料信息时,为什么屏幕上没有显示任何内容,只有背景?

java - 在 JPanel 中将 JLabel 居中

ios - 标题为 UIImage 的导航栏

iphone - 如何在 iphone 应用程序中将导航 Controller 的后退按钮与其左角对齐

安卓 N : My app call onDestroy() when entering multi-windows mode

java - android - 带 ScrollView 的并排按钮

css - 如果内联 block 元素上的高度足够,则强制换行

html - Flexbox 布局模式 1/3

ios - 如何以编程方式在 uinavigationbar subview 上添加约束

android - Android 4.0 或更高版本的应用程序崩溃