Android的资源获取的相关方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012915833/article/details/73740285

AttributeSet

1.String getAttributeName(int index)

获取属性名称


2.String getAttributeValue(int index)

获取属性值,如果值是引用资源,则为@+资源ID值

如android:color="@color/white",假设R.color.white为00003322,则getAttributeValue获取的值为“@00003322”


3.int getAttributeResourceValue(int index,int defaultValue)

获取属性资源值,如果值是引用资源,则返回引用资源的id值,如果不是,则返回defaultValue

如android:color="@color/white",假设R.color.white为00003322,则getAttributeValue获取的值为00003322


3.int getAttributeResourceValue(String namespace, String attribute,
                                         int defaultValue)

获取属性资源值,namespace命名空间,attribute属性名,defaultValue默认值

如app:color,则调用getAttributeResourceValue("app","color",0);


5.int getAttributeNameResource(int index)

获取属性资源id值

如属性android:color,返回值为R.attr.color


6.getStyleAttribute()

获取style属性值,相当于getAttributeResourceValue(null,"style",0)


Resource

1.String getResourceEntryName(int resId)

获取资源id对应的名称

如getResourceEntryName(R.color.white),返回"white"


2.String getResourceTypeName(int resId)

获取资源id对应类型
如getResourceEntryName(R.color.white),返回"color"


3.String getResourcePackageName(int resId)

获取资源id对应的包名
如包名为com.example,则getResourcePackageName(R.color.white)返回值为"com.example"


4.String getResourceName(int resId)

获取资源id对应名称,格式为package:type/entry

如包名为com.example,则getResourceEntryName(R.color.white)返回值为"com.example:color/white"


猜你喜欢

转载自blog.csdn.net/u012915833/article/details/73740285