上单击更改TextView的背景颜色 [英] Change Background Color of TextView on Click
本文介绍了上单击更改TextView的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要改变一个TextView的背景颜色。
I need to change the background color of a TextView.
使用ColorStateList什么,我可以改变,但背景颜色不接受ColorStateList字体颜色
the font color using ColorStateList what I can change, but the background color does not accept ColorStateList
lblEtiqueta.setTextColor (new ColorStateList (
new int [] [] {
new int [] {android.R.attr.state_pressed}
new int [] {android.R.attr.state_focused}
new int [0]
}, new int [] {
Color.rgb (255, 128, 192),
Color.rgb (100, 200, 192),
Color.White,
}
));
如何让背景颜色?
how to make the background color?
TextView控件是在运行时动态创建的。
TextView control is created dynamically at runtime.
在此先感谢。
推荐答案
您将需要设置backgroundDrawable为TextView的。我只是做了我的状态列出了XML,它会是这样的:
You will need to set the backgroundDrawable for the TextView. I've only done my state lists in XML and it would be something like this:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<color android:color="#00ff00" />
</item>
<!-- And so on -->
</selector>
据我所知,从文档,如果你想在Java的$ C $国家名单C,你将需要使用的 StateListDrawable
这篇关于上单击更改TextView的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文