在values目录里面创建attrs.xml文件,名字必须是attrs
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="cn.jianhaozhan.ui.SettingView">
<attr name="st_title" format="string"/>
<attr name="st_des_on" format="string"/>
<attr name="st_des_off" format="string"/>
</declare-styleable>
</resources>
给样式文件增加命名空间
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:jianhaozhan="http://schemas.android.com/apk/res/cn.jianhaozhan.activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#8866ff00"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="设置中心"
android:textSize="22sp" />
<cn.jianhaozhan.ui.SettingView
android:id="@+id/sv_setting_update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
jianhaozhan:st_title="提示更新"
jianhaozhan:st_des_on="提示更新已开启"
jianhaozhan:st_des_off="提示更新已关闭"
></cn.jianhaozhan.ui.SettingView>
</LinearLayout>
xmlns:jianhaozhan="http://schemas.android.com/apk/res/cn.jianhaozhan.activity"
xmlns:后面的jianhaozhan可以任意写。路径res后面跟的是清单文件中写的包名。