java XML 中是否有等效于 setColorFilter() 的方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13137612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there an equivalent to setColorFilter() in XML?
提问by Jecimi
I'd like to know if a ColorFilter
can be set in the XML of a View
or if the only way is to use setColorFilter()
in Java.
我想知道是否ColorFilter
可以在 a 的 XML 中设置 aView
或者是否唯一的方法是setColorFilter()
在 Java 中使用。
采纳答案by Martin Christmann
According to the documentation http://developer.android.com/reference/android/graphics/ColorFilter.htmlthere is no corresponding xml version for ColorFilter.
根据文档 http://developer.android.com/reference/android/graphics/ColorFilter.html,ColorFilter没有相应的 xml 版本。
I also searched for attributes in documentation with the keys 'color' and 'filter' http://developer.android.com/reference/android/R.attr.html
我还使用键“颜色”和“过滤器”在文档中搜索属性 http://developer.android.com/reference/android/R.attr.html
回答by GDanger
There is; it's called tint. It's not available on View
but is on ImageView
and ImageButton
.
有; 它被称为tint。它在 上不可用,View
但在ImageView
和上可用ImageButton
。
If you want to use it with a selector
this answerhelped me a bunch.
如果你想使用它,selector
这个答案对我有很大帮助。
回答by Yogesh Rathi
You can use:
您可以使用:
android:tint="@color/white"
回答by Felipe
There is no xml equivalent, but on API level 21 you can use the tint attribute. But I assume you don't want to target 21+ devices. Not in a few years at least.
没有 xml 等效项,但在 API 级别 21 上,您可以使用 tint 属性。但我假设您不想针对 21 台以上的设备。至少几年内不会。
回答by bentzy
If you want to use tint and support older versions you can Add com.android.support:appcompat-v7:23.2.1
to build.gradle (Don't forget to update Android SDK)
如果你想使用 tint 并支持旧版本,你可以添加com.android.support:appcompat-v7:23.2.1
到 build.gradle (不要忘记更新 Android SDK)
Thanks for the tip @sherpya!
感谢@shrpya 的提示!