[英]Change Background Color of TextView on Click
我需要更改TextView的背景颜色。
使用ColorStateList的字体颜色我可以改变,但背景颜色不接受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,
}
));
如何制作背景色?
TextView控件是在运行时动态创建的。
提前致谢。
您需要为TextView设置backgroundDrawable。 我只用XML完成了我的状态列表,它将是这样的:
<?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代码中执行状态列表,则需要使用StateListDrawable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.