1、在values目录下,创建attrs.xml文件
2、在attrs文件中声明declare-styleable节点
<attr name="_leftImage" format="reference"></attr> 引入,图片 .getDrawable
<attr name="_midTextColor" format="color"/> 颜色 .getColor
<attr name="_midTextSize" format="dimension"/> 大小,适配 .getDimension
<attr name="_midTextHint" format="string"/> 字符串 .getString
name:属性名称,这个名称千万不能和系统的属性名称重复
3、使用
参考代码
context.obtainStyledAttributes(AttributeSet, R.styleable.attrs文件中的name名);
4、在布局文件中使用
注意命名空间问题