繁体   English   中英

如何以编程方式为 Textview 设置`app:backgroundTint`?

[英]how to set `app:backgroundTint` for Textview programatically?

我正在尝试将色调添加到我的普通Textview而不是AppCompatTextView 我可以使用app:backgroundTint在 xml 中添加 backgroundTint。 有没有办法以编程方式为Textview本身做同样的Textview 。(我的目标是kitkat支持)

注意:我有更多Textview 所以改变所有这些将结束工作

setSupportButtonTintList仅适用于AppCompat控件。 setBackgroundTintListkitkat中没有显示结果

这对我有用

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM