动态更改导航视图项的颜色Android [英] Change Navigation View Item Color Dynamically Android

查看:190
本文介绍了动态更改导航视图项的颜色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屋!

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