gpt4 book ai didi

android - 动态更改导航 View 项目颜色Android

转载 作者:IT老高 更新时间:2023-10-28 23:38:45 26 4
gpt4 key购买 nike

我想构建一个抽屉导航,其中每个项目都有不同的选择颜色(图标颜色和文本颜色),就像 google play 商店一样:

enter image description here

我不确定他们是如何解决这个问题的,我认为他们使用不同的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com