【发布时间】:2013-03-01 05:49:23
【问题描述】:
我需要以编程方式这样做的原因是文本颜色是下载的,而不是在 xml 中预先定义的。我读了这个 Replace selector images programmatically
我只需要知道
StateListDrawable states = new StateListDrawable();
states.addState(new int[] {android.R.attr.state_pressed},
getResources().getDrawable(R.drawable.pressed));
怎么变成
states.addState(new int[] {android.R.attr.state_pressed},**theMethodImLookingFor**("#e3bb87"));
忘记getResources().getColor(R.color.anycolor),xml中没有定义颜色
【问题讨论】:
-
你可以尝试使用 text.setTextColor(0xff00ff00);
-
这是一个有趣的观点。我建议从标题中删除明确的“#e3bb87”,以便人们可以轻松找到任何颜色。
标签: android textview android-drawable android-selector