android - 在具有全屏 Activity 的 Android Lollipop 上设置导航栏颜色

标签 android android-activity android-5.0-lollipop navigationbar

有没有办法在全屏 Activity 中设置导航栏颜色?

if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_color));

我的主题风格中的这一行:

<item name="android:navigationBarColor" tools:targetApi="21">#E64A19</item>

两者都会在我的 Activity 布局上方产生相同的透明导航栏...

代码:

Activity :

@Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                //Remove title bar
                this.requestWindowFeature(Window.FEATURE_NO_TITLE);

                //Remove notification bar
                this.getWindow()
    .setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

                setContentView(R.layout.activity_account);

                if (getResources().getBoolean(R.bool.portrait_only)) {
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }

                if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    getWindow()
        .setNavigationBarColor(getResources().getColor(R.color.Theme_color));
                }


                //other code ... (irrelevant)

主题:

<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowBackground">@null</item>
        <item name="metaButtonBarStyle">@style/ButtonBar</item>
        <item name="metaButtonBarButtonStyle">@style/ButtonBarButton</item>
        <item name="android:navigationBarColor" tools:targetApi="21">#E64A19</item>
</style>

结果是一个黑色的导航栏。但我想要一个橙色(#E64A19)导航栏。

结果: old result set navbar-color

最佳答案

我的解决方案:

当我删除 parent="android:Theme.NoTitleBar" 后,问题出在生成的代码(XML 主题)上。我的主题样式的属性(以及除 <item name="android:navigationBarColor" tools:targetApi="21">#E64A19</item> 之外的其他所有内容)我的导航栏变成了橙色!

结果: screenshot with working navbar-color

关于android - 在具有全屏 Activity 的 Android Lollipop 上设置导航栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29794280/

相关文章:

android - IntelliJ/Android Studio - 如何激活 proguard 来混淆代码 - 一步一步?

android - RecyclerView 滚动时改变高度如何解决?

Android 多处理程序设计

android - 倒数计时器通知

android - 升级到 Support Library v21 后,ActionBar aka Toolbar 为黑色

android - 如何通过 NDK 访问 Android Lollipop DocumentFile 文件?

android - 具有 ViewPager 和框架布局的 ActionBar 选项卡

android - React Viro,点击很长时间触发释放

Android - 应用程序离开时返回主 Activity

android - 使用 Lollipop 在从右到左的语言环境中进行自动布局镜像