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

问题描述 投票:0回答:2

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

注意:我有更多的Textview。所以改变所有这些都将超过工作

setSupportButtonTintListonly适用于AppCompat控件。 setBackgroundTintList没有显示kitkat的结果

java android android-layout android-appcompat android-design-library
2个回答
2
投票

注意

Added in version 23.1.1所以你不能在19岁使用

对于AppCompat,您可以使用setSupportButtonTintList

void setSupportButtonTintList(ColorStateList tint)

tvOBJ.setSupportButtonTintList(ContextCompat.getColorStateList(CurrentActivity.this, R.color.your_color));

0
投票

你可以使用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)
© www.soinside.com 2019 - 2024. All rights reserved.