ITeye博客

在代码中获取Android theme中的attr属性值

OliveExcel · 2015-07-16 20:31 · 移动开发 · Markdown

Android的Theme是由各种attr组合而成, 每个attr对应了这个属性的一个引用, 这个引用又可以是各种东西.

 

在某些情况下, 我们需要获取非自定义的主题下某个属性的内容 (比如拿到系统默认的配色colorAccent), 操作方式举例一则:

int defaultColor = 0xFF000000;
int[] attrsArray = { andorid.r.attr.colorAccent };
TypedArray typedArray = context.obtainStyledAttributes(attrsArray);
int accentColor = typedArray.getColor(0, defaultColor);

// don't forget the resource recycling
typedArray.recycle();

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。