码迷,mamicode.com
首页 > 移动开发 > 详细

【技巧】获取android xml文件中控件的属性的值

时间:2014-09-27 00:11:49      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:android   http   文件   sp   div   c   r   ef   bs   

当重写ImageView的时候需要获取android:src的值

可以通过:getAttributeResourceValue("http://schemas.android.com/apk/res/android","src",0);获取

如果是自定义的属性,比如bitmap

通过:getAttributeResourceValue(null,"bitmap",0);

 

int android.util.AttributeSet.getAttributeResourceValue(String namespace, String attribute, int defaultValue) 方法
 
参数:
  namespace: 属性的位置,android内置属性的默认位置在http://schemas.android.com/apk/res/android,自定义属性的就直接null就好
  attribute: 属性的名字
  defaultValue: 如果找不到该属性的话,返回啥
 
 

【技巧】获取android xml文件中控件的属性的值

标签:android   http   文件   sp   div   c   r   ef   bs   

原文地址:http://www.cnblogs.com/kirno/p/3995689.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!