[英]how to set `app:backgroundTint` for Textview programatically?
我正在尝试将色调添加到我的普通Textview
而不是AppCompatTextView
。 我可以使用app:backgroundTint
在 xml 中添加 backgroundTint。 有没有办法以编程方式为Textview
本身做同样的Textview
。(我的目标是kitkat支持)
注意:我有更多Textview
。 所以改变所有这些将结束工作
setSupportButtonTintList
仅适用于AppCompat
控件。setBackgroundTintList
在kitkat中没有显示结果
这对我有用
someTextView.getBackground().setTint(yourIntColor);
注意
Added in version 23.1.1
所以你不能在 19 中使用
对于 AppCompat ,您可以使用setSupportButtonTintList
void setSupportButtonTintList (ColorStateList tint)
tvOBJ.setSupportButtonTintList(ContextCompat.getColorStateList(CurrentActivity.this, R.color.your_color));
您可以使用ViewCompat.setBackgroundTintList( )
val states = arrayOf(intArrayOf(android.R.attr.state_enabled))
val colors = intArrayOf(Color.RED)
val colorStateList = ColorStateList(states, colors)
ViewCompat.setBackgroundTintList(myView, colorStateList)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.