当前位置: 代码迷 >> Android >> android中自定义属性三方法
  详细解决方案

android中自定义属性三方法

热度:97   发布时间:2016-05-01 16:56:59.0
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中就存放了自定义的属性

}

  相关解决方案