以编程方式将颜色#e3bb87&;添加到StateListDrawable [英] Add Color "#e3bb87" to StateListDrawable programmatically
本文介绍了以编程方式将颜色#e3bb87&;添加到StateListDrawable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要以编程方式执行此操作的原因是文本颜色是下载的,而不是在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中定义的
推荐答案
您可以使用此命令:
states.addState(new int[] {android.R.attr.state_pressed},
new ColorDrawable(Color.parseColor("#e3bb87")));
这篇关于以编程方式将颜色#e3bb87&;添加到StateListDrawable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文