AttributeSet 帮助类,读取Android的属性---1
来源:互联网 发布:淘宝禁售兴奋剂有哪些 编辑:程序博客网 时间:2024/06/15 13:06
import android.content.Context;import android.graphics.Color;import android.util.AttributeSet;import android.util.DisplayMetrics;import android.util.TypedValue;/** * AttributeSet 帮助类,读取Android的属性 * * */public class AttributeHelper {public static final String ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android";private Context mContext;private AttributeSet mAttrs;public AttributeHelper(Context context, AttributeSet attrs) {mContext = context;mAttrs = attrs;}/** * 判断是否有指定的属性 * * @param attribute * * @return true 有,false 没有 */public boolean hasAttr(String attribute){return getValue(attribute)!=null;}/** * 获取指定属性的值,不一定是真正的值,比如 15sp 返回的是15sp而不是15 * * @param attribute * * @return 返回字符串或者null */public String getValue(String attribute) {if (mAttrs == null) {return null;}String string = mAttrs.getAttributeValue(ANDROID_NAMESPACE, attribute);return string;}/** * 获取 string值, * * @param attribute * 属性名称 * * @return 如果找到返回相应的值,否则返回null */public String getString(String attribute) {String string = getValue(attribute);if (string != null && string.startsWith("@")) {// 资源文件string = mContext.getResources().getString(Integer.parseInt(string.substring(1)));}return string;}/** * 获取文本数组 * * @param attribute * @return 如果没有找到,返回null */public String[] getTextArray(String attribute) {String string = getValue(attribute);if (string != null && string.startsWith("@")) {// 资源文件return mContext.getResources().getStringArray(Integer.parseInt(string.substring(1)));}return null;}/** * 获取 string值, * * @param attribute * 属性名称 * * @return 如果找到返回相应的值,否则返回false */public boolean getBoolean(String attribute) {String string = getValue(attribute);if (string != null && string.startsWith("@")) {// 资源文件return mContext.getResources().getBoolean(Integer.parseInt(string.substring(1)));}return Boolean.parseBoolean(string);}
0 0
- AttributeSet 帮助类,读取Android的属性---1
- AttributeSet 帮助类,读取Android的属性---2
- Android-自定义AttributeSet属性
- android 自定义AttributeSet属性
- 读取layout属性-AttributeSet TypedArray
- android使用自定义属性AttributeSet
- android使用自定义属性AttributeSet
- 读取属性:TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs,...)
- android AttributeSet
- Android使用AttributeSet自定义控件的方法
- Android使用AttributeSet自定义控件的方法
- Android使用AttributeSet自定义控件的方法
- Android使用AttributeSet自定义控件的方法
- Android使用AttributeSet自定义控件的方法
- Android使用AttributeSet自定义控件的方法
- Android使用AttributeSet自定义控件的方法
- Android使用AttributeSet自定义控件的方法
- Android使用AttributeSet自定义控件的方法
- Nodejs http、url模块
- 正则与NSPredicate 应用
- HDU2091(预处理+格式控制)
- 用MyEclipse2014自动加载ssh无法连接数据库问题
- ubuntu 13.04 安装 JDK
- AttributeSet 帮助类,读取Android的属性---1
- 二叉树(11)----求二叉树的镜像,递归和非递归方式
- AttributeSet 帮助类,读取Android的属性---2
- oc nil, Nil, NULL和NSNull的区别
- 微软完整的SQLHelper
- 【灌水】天草逆向, esp定律脱壳
- RedHat Enterprise Linux挂载新硬盘
- 我和nupt集训队的故事
- iSCSI技术白皮书