android中的自定义属性的运用细节

来源:互联网 发布:湖南软件职业学院吧 编辑:程序博客网 时间:2024/05/24 07:26

一. 自定义命名空间

布局文件xml中:xmlns:androidtest = "http://schemas.android.com/apk/res/工程包名"

二. 创建attrs.xml文件

通过包名找到工程,从而寻找到资源文件,在res/values下新建attrs.xml文件用于存放属性的配置文件:<resources>  <declare-styleable name = "ContentCenterItemView">    <attr name="title" format="string"/>    <attr name="content" format="string"/>  </declare-styleable></resources>

三.在自定义组件中使用自定义属性

<com.wangji.telephone.view.ContentCenterItemView  android:layout_width="fill_parent"  android:layout_height="wrap_content"  androidtest:content="content1.2.3"  androidtest:title="title1.2.3"></com.wangji.telephone.view.ContentCenterItemView>
0 0
原创粉丝点击