<declare-styleable name="MyTextView"><attr name="content" format="string" /><attr name="contentColor" format="color" /><attr name="contentSize" format="dimension" /></declare-styleable>3. 在两个参数的构造方法中,读取开发者在布局文件中使用的属性值代码:TypedArray o = context.obtainStyledAttributes(attrs, R.styleable.MyTextView);mContent = o.getString(R.styleable.MyTextView_content);mColor = o.getColor(R.styleable.MyTextView_contentColor, Color.BLACK);mDimen = o.getDimension(R.styleable.MyTextView_contentSize, 18);o.recycle();
myapp:contentColor="#0000FF"myapp:contentSize="30sp"
原文:http://www.cnblogs.com/vijay/p/3558292.html