解决android.R.attr.listChoiceIndicatorMultiple找不到的问题

因为项目实现,需要动态的调用CheckTextView.setCheckMarkDrawable(Drawable)

当调用.setCheckMarkDrawable(android.R.attr.listChoiceIndicatorMultiple)时,系统总是提示

android.content.res.Resources$NotFoundException: Resource ID XXXXX

 

此时通过如下方法可以解决:

通过主题获取界面元素

int[] attrs = { android.R.attr.listChoiceIndicatorMultiple };
TypedArray ta = getContext().getTheme().obtainStyledAttributes(attrs);
Drawable indicator = ta.getDrawable(0);
name.setCheckMarkDrawable(indicator);
ta.recycle();

posted @ 2013-12-16 22:39  慕容渊  阅读(938)  评论(0)    收藏  举报