动态更改导航视图项的颜色Android [英] Change Navigation View Item Color Dynamically Android
问题描述
我想构建一个导航抽屉,其中每个项目都具有与Google Play商店不同的选择颜色(图标色调和文本颜色):
I'd like to build a navigation drawer where each item has a different selection color (the icon tint and text color) as the google play store has:
我不确定他们如何解决此问题,我认为他们在不同的抽屉中使用不同的活动.我想使用片段,并且想要更改图标的色调和文本颜色.有什么想法可以做到这一点吗?我使用的是Google的设计支持库和一个带有导航视图的抽屉布局.
I'm not sure how they've solved this, I think they use different activities with different drawers. I want to use fragments and I want to change the icon tint and text color. Any ideas how I can do this? I'm using google's design support library and a drawer layout with a navigation view in there.
推荐答案
在NavigationView
中将app:itemIconTint
用于图标,将app:itemTextColor
用于textColors
use app:itemIconTint
in your NavigationView
for icons and use app:itemTextColor
for textColors
示例:
drawable/navigation_text_color
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is used when the Navigation Item is checked -->
<item android:color="#009688" android:state_checked="true" />
<!-- This is the default text color -->
<item android:color="#E91E63" />
</selector>
和layout
:
<android.support.design.widget.NavigationView
.
.
app:itemTextColor="@drawable/navigation_text_color"/>
这篇关于动态更改导航视图项的颜色Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!