我想构建一个抽屉导航,其中每个项目都有不同的选择颜色(图标颜色和文本颜色),就像 google play 商店一样:
我不确定他们是如何解决这个问题的,我认为他们使用不同的 Activity 和不同的抽屉。我想使用 fragment ,我想更改图标色调和文本颜色。任何想法我怎么能做到这一点?我正在使用谷歌的设计支持库和带有导航 View 的抽屉布局。
最佳答案
在 NavigationView
中使用 app:itemIconTint
作为图标,使用 app:itemTextColor
作为 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>
和布局
:
<android.support.design.widget.NavigationView
.
.
app:itemTextColor="@drawable/navigation_text_color"/>
关于android - 动态更改导航 View 项目颜色Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30967851/