Android res资源相关的方法

AttributeSet attrs

1.属性名(android:layout_width中的”layout_width“,android:textColor中的”textColor“)

1
String attrName = attrs.getAttributeName(i);

2.属性值(“@1234567”)

1
String attrValue = attrs.getAttributeValue(i);

3.资源id(“@1234567”中的1234567)

1
int id = Integer.parseInt(attrValue.substring(1));

4.属性值的引用名(@color/red中的“red”)

1
String entryName = context.getResources().getResourceEntryName(id);

5.类型名(@color/red中的color)

1
String typeName = context.getResources().getResourceTypeName(id);
如果您觉得这篇文章不错,可以打赏支持下哦,谢谢