【问题标题】:Navigation bar buttons color导航栏按钮颜色
【发布时间】:2017-12-07 21:55:28
【问题描述】:

我想在我的应用程序中更改导航按钮的颜色,

我尝试使用window.setNavigationBarColor(@ColorInt int color),但这种方法只改变了条形图的背景。有什么想法吗?

【问题讨论】:

标签: android layout uinavigationbar galaxy


【解决方案1】:

您可以使用以下函数动态更改导航颜色。基本上它检查给定的 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;
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-27
相关资源
最近更新 更多