读书人

经过代码设置color 类型的selector

发布时间: 2013-03-22 09:49:50 作者: rapoo

通过代码设置color 类型的selector

在代码中通过资源id设置selector类型的颜色值往往不成功,需要用下面这种方式来添加selector资源,然后这只给指定的View

try {
XmlResourceParser xrp = getResources().getXml(R.color.father_btcolor);
ColorStateList cl = ColorStateList.createFromXml(getResources(), xrp);
} catch (Exception ex) {}
if(cl != null){

tl.setTextColor(cl);
}

读书人网 >移动开发

热点推荐