Android自定义属性-format

string 字符串

  • 定义
                
  • 获取
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyTextView);        //获取文字        String textName = typedArray.getString(R.styleable.MyTextView_my_textname);        this.setText(textName);
  • 使用
 

dimension 尺寸值

  • 定义
                                
  • 获取
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyTextView);        //获取文字        String textName = typedArray.getString(R.styleable.MyTextView_my_textname);        this.setText(textName);        //获取文字大小        float textsize = typedArray.getDimensionPixelSize(R.styleable.MyTextView_my_textsize, 14);        this.setTextSize(textsize);
  • 使用
 

color:颜色值

  • 定义
                                                
  • 获取
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyTextView);        //获取文字        String textName = typedArray.getString(R.styleable.MyTextView_my_textname);        this.setText(textName);        //获取文字大小        float textsize = typedArray.getDimensionPixelSize(R.styleable.MyTextView_my_textsize, 14);        this.setTextSize(textsize);        //获取文字颜色        int color = typedArray.getColor(R.styleable.MyTextView_my_textcolor, 0xff00ff00);        this.setTextColor(color);
  • 使用
 

reference:参考某一资源ID。

  • 定义
                                                                    
  • 获取
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyTextView);        //获取文字        String textName = typedArray.getString(R.styleable.MyTextView_my_textname);        this.setText(textName);        //获取文字大小        float textsize = typedArray.getDimensionPixelSize(R.styleable.MyTextView_my_textsize, 14);        this.setTextSize(textsize);        //获取文字颜色        int color = typedArray.getColor(R.styleable.MyTextView_my_textcolor, 0xff00ff00);        this.setTextColor(color);        //获取背景        int resourceId = typedArray.getResourceId(R.styleable.MyTextView_my_background, R.mipmap.ic_launcher);        this.setBackgroundResource(resourceId);
  • 使用
 
mytextview.png

boolean:布尔值.

  • 定义
                        
  • 获取
  • 使用

integer:整型值

  • 定义
                        
  • 获取
  typedArray.getInteger(R.styleable.名称,默认值)
  • 使用

float:浮点值

  • 定义
        
  • 获取
typedArray.getFloat(R.styleable.名称,默认值)
  • 使用

fraction:百分数

  • 定义
            
  • 使用

enum:枚举值

  • 定义
                
  • 使用

flag:位或运算

  • 定义
  • 使用
                        

属性定义时可以指定多种类型值

个人主页:

https://ln0491.github.io/
http://ln0491.coding.me/
博客:
http://blog.csdn.net/ko0491
http://www.cnblogs.com/liunanjava/

更多相关文章

  1. Android(安卓)Training - 使用IntentService执行任务(Lesson 3 -
  2. Android中一直走马灯效果的TextView
  3. 【Android】编译CM10遇到的错误解决方案
  4. android 获取 json 数据
  5. android 滑动动画效果
  6. 箭头函数的基础使用
  7. NPM 和webpack 的基础使用
  8. Python list sort方法的具体使用
  9. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程

随机推荐

  1. android设置保持窗口常亮
  2. Android(安卓)Okhttp的基础使用版
  3. Android(安卓)滑动开关控件
  4. Version Code 版本设置
  5. android 开源项目(城市定位)
  6. Android中下载文件的使用
  7. Android(安卓)学习之- 单选按钮、复选框
  8. Android(安卓)Applications Tutorial 22.
  9. android security and policy
  10. android canvas 画闹钟 圆弧