<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CustomViewStyle">
<attr name="textColor" format="color"/>
<attr name="textSize" format="dimension"/>
<attr name="layout_width" format="dimension"/>
<attr name="text" format="string"/>
<attr name="button" format="reference"/><!-- 参考某一资源ID -->
<attr name="buttonWidth" format="dimension"/>
<attr name="background1" format="reference|color"/><!-- 多类型 -->
<attr name="src" format="reference"/><!-- 参考某一资源ID -->
<attr name="checked" format="boolean"/>
</declare-styleable>
<!-- 枚举 -->
<declare-styleable name="名称">
<attr name="orientation">
<enum name="horizontal" value="0"/>
<enum name="vertical" value="1"/>
</attr>
</declare-styleable>
</resources>
public MyView(Context context,AttributeSet attrs)
{
super(context,attrs);
mPaint = new Paint();
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.CustomViewStyle);
int textColor = a.getColor(R.styleable.CustomViewStyle_textColor, 0XFFFFFFFF);
float textSize = a.getDimension(R.styleable.CustomViewStyle_textSize, 36);
mPaint.setTextSize(textSize);
mPaint.setColor(textColor);
a.recycle();
}