以编程方式更改Android EditText的颜色 [英] Changing tint color of Android EditText programmatically
问题描述
我试图在运行时以编程方式更改 EditText
视图的着色颜色.基本上,我想更改通常用作?attr/colorControlNormal
的内容,例如 1中指定的Alpha开头是可见的.
这是仅在第一个 EditText
上设置色彩颜色的结果:
所以我的问题是:如何以编程方式将着色正确地应用于 EditText
?
使用新引入的 android.support.v4.graphics.drawable.DrawableCompat#setTint
可以设置颜色.>
I am trying to change the tinting color of an EditText
View programmatically during runtime. Basically i want to change what you would usually apply as ?attr/colorControlNormal
like in the default background drawable.
Changing the background tint does not correctly apply by just setting a new ColorsStateList
with one color:
editText.setBackgroundTintList( ColorStateList.valueOf( color ) );
For one the result is applied to all EditText
although the tint list is applied and internally mutates the drawable. Also the alpha as specified in the default background 1 is visible at the beginning.
Here is the outcome of setting the tint color on just the first EditText
:
So my question would be: How can I properly apply the tint programmatically to an EditText
?
With the newly introduced android.support.v4.graphics.drawable.DrawableCompat#setTint
setting the color is now possible.
这篇关于以编程方式更改Android EditText的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!