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

标签 android drawerlayout androiddesignsupport navigationview

我想构建一个抽屉导航,其中每个项目都有不同的选择颜色(图标颜色和文本颜色),就像 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/

相关文章:

android - Apache Cordova 错误的 Visual Studio 工具

android - 如何修复appcompat gradle错误? Android 3.4

Android Jetpack Compose 全宽抽屉

android - 使用 ScrollView(和 NestedScrollView)时 CollapsingToolbarLayout 不折叠

php - 将 android 设备连接到 SqlServer 2005 时出现 JSON 解析错误

java - Android map View 地理编码器语法

android - 如何在触摸外部时关闭 android DrawerLayout?

android - 创建抽屉布局的标题?

android - 如何更改导航 View 项目的文本大小?

android - 找不到应用程序 :layout_scrollflags from CollapsingToolbarLayout 的资源 ID