单击时更改TextView的背景颜色
我需要更改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完成了我的状态列表,它将是这样的:
-
根据我的理解,从文档中如果要在Java代码中执行状态列表,则需要使用StateListDrawable