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"
更多相关文章
- [Android(安卓)Training视频系列]6.1 Saving Key-Value Sets
- (android)关于ListFragment使用
- Flutter底部导航栏BottomNavigationBar
- 手机安全卫士开发系列(7)——知识点整理(1)
- android intent.setDate方法
- android 在java代码中动态设置控件的位置和设置片大小
- RelativeLayout实现百分比布局
- Android(安卓)DSL简介
- Android(安卓)5.0以上Button去掉阴影