android中自定义属性三方法
android中自定义属性三步骤
1.values目录下创建一个attrs.xml文件 以如下方式声明 <attr name="myname" format="String" />
2.在一个style的item中以如下方式引用 <item name="myname">"我的名字"</item>
3.经过上两步就可以在自己的View中使MyView(Context context, AttributeSet attrs,int myStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.TestView, myStyle, 0);
... ...//这个a中就存放了自定义的属性
}