添加颜色"#e3bb87"以编程方式StateListDrawable [英] Add Color "#e3bb87" to StateListDrawable programmatically
本文介绍了添加颜色"#e3bb87"以编程方式StateListDrawable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我之所以要做这样的编程是用于文字的颜色被下载,而不是在XML定义pre。我读这
替代选择图像编程
The reason I need to do this programmatically is that the text color is downloaded and not pre defined in the xml. I read this 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屋!
查看全文