禁用图标colorStateList在NavigationView [英] Disable icon colorStateList in NavigationView

查看:257
本文介绍了禁用图标colorStateList在NavigationView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序。今天,我不只是有一个单一的颜色的图标,但在某些情况下,两种颜色取决于数据的状态,在我的应用程序。这意味着我不能使用NavigationView默认着色行为。

看起来像新的NavigationView,除非我指定一个ColorStateList我的图标列表中的使用,默认ColorStateList会为我做它用我的colorPrimary等在我的主题定义。

有没有办法,我强迫NavigationView停止着色我的图标?

解决方案
  

有没有办法,我强迫NavigationView停止着色我   图标?

有肯定的是。你可以这样做编程方式使用<一个href="https://developer.android.com/reference/android/support/design/widget/NavigationView.html#setItemIconTintList(android.content.res.ColorStateList)"><$c$c>NavigationView.setItemIconTintList.

你可以在你的 XML 布局使用<一个这样做href="https://developer.android.com/reference/android/support/design/widget/NavigationView.html#attr_android.support.design:itemIconTint"><$c$c>NavigationView.itemIconTint属性。

编程

  yourNavigationView.setItemIconTintList(空);
 

XML

 &LT; android.support.design.widget.NavigationView
    ...
    应用程序:itemIconTint =@机器人:彩色/黑白
    ... /&GT;
 

结果

In my app today i have icons which doesn't just have a single color, but in some cases two colors depending on the data state in my app. This means i cant use the default tinting behavior in NavigationView.

It looks like with the new NavigationView, unless i specify a ColorStateList for my icons used in the list, a default ColorStateList will be made for me which uses my colorPrimary etc defined in my theme.

Is there no way for me to force NavigationView to stop tinting my icons?

解决方案

Is there no way for me to force NavigationView to stop tinting my icons?

There sure is. You can do so programmatically using NavigationView.setItemIconTintList.

And you can do so in your XML layout by using the NavigationView.itemIconTint attribute.

Programmatically

yourNavigationView.setItemIconTintList(null);

From XML

<android.support.design.widget.NavigationView
    ...
    app:itemIconTint="@android:color/black" 
    ... />

Results

这篇关于禁用图标colorStateList在NavigationView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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