NavigationView 如果图标上色,则会对图标进行颜色着色。 我的图标为绿色,在NavigationView中,它是灰色。这是如何工作的?
我想在其他视图中自己做,但我没有找到NavigationView如何做到这一点。
答案 0 :(得分:3)
这here解释了AppCompat对drawable的着色。这是你在找什么?
Lollipop中添加的Drawable着色方法是 对于让您动态着色资产非常有用。 AppCompat有 它自己在v21支持库中实现,我们已经 现在将其提取到支持-v4中的DrawableCompat中,供大家使用 使用。重要的是要知道它是如何工作的。
Drawable drawable = ...; // Wrap the drawable so that future tinting calls work // on pre-v21 devices. Always use the returned drawable. drawable = DrawableCompat.wrap(drawable); // We can now set a tint DrawableCompat.setTint(drawable, Color.RED); // ...or a tint list DrawableCompat.setTintList(drawable, myColorStateList); // ...and a different tint mode DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_OVER);
或者,如果您只想为ImageView着色,可以这样做:
ImageView image = (ImageView) findViewById(R.id.image);
image.setColorFilter(...);