一. 自定义命名空间
布局文件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>