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();
本文介绍如何在Android中获取非自定义主题下特定属性的内容,例如系统默认的颜色属性colorAccent。通过示例代码展示了使用TypedArray从当前上下文中获取指定属性值的方法,并确保资源被正确回收。

5608

被折叠的 条评论
为什么被折叠?



