Android的资源获取的相关方法

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"


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值