Android 棒棒糖更改导航栏颜色 [英] Android lollipop change navigation bar color

查看:37
本文介绍了Android 棒棒糖更改导航栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我需要更改底部导航栏的颜色.我看了很多帖子,但找不到解决方案.我正在使用 appCompat 库.

In my app I need to change the bottom navigation bar color. I watched many post but cant find with the solution. I am using appCompat library.

v21/styles.xml

v21/styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light">
       <item name="android:windowBackground">@drawable/bgpreview</item>
       <item name="android:colorPrimary">@color/MyColor</item>
       <item name="android:colorPrimaryDark">@color/MyColor</item>
       <item name="android:windowContentOverlay">@null</item>
       <item name="android:textColorPrimary">@color/MyColor</item>
       <item name="colorAccent">@color/MyColor</item>
       <!-- darker variant for the status bar and contextual app bars -->
       <item name="android:windowContentTransitions">true</item>
       <item name="android:windowAllowEnterTransitionOverlap">true</item>
       <item name="android:windowAllowReturnTransitionOverlap">true</item>
       <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
       <item name="android:windowSharedElementExitTransition">@android:transition/move</item>

       <item name="windowActionBar">false</item>
       <item name="android:textAllCaps">false</item>

</style>

推荐答案

可以在styles.xml中使用

<item name="android:navigationBarColor">@color/theme_color</item>

window.setNavigationBarColor(@ColorInt int color)

http://developer.android.com/reference/android/view/Window.html#setNavigationBarColor(int)

请注意,该方法是在 Android Lollipop 中引入的,不适用于 API 版本 <21.

Note that the method was introduced in Android Lollipop and won't work on API version < 21.

第二种方法(适用于 KitKat)是在清单中将 windowTranslucentNavigation 设置为 true 并在导航栏下方放置一个彩色视图.

The second method (works on KitKat) is to set windowTranslucentNavigation to true in the manifest and place a colored view beneath the navigation bar.

这篇关于Android 棒棒糖更改导航栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆