Write in 1.attrs.xml: under the Values folder.
<?xml version= "1.0" encoding= "Utf-8"?><resources> <declare-styleable name= "testattr" > <attr name= "name" format= "Reference"/> <attr name= "age" > <flag name= "child" value= "/>" <flag name= "Young" value= "/> <flag name=" oldman "value="/> </attr> < attr name= "TextSize" format= "Dimension"/> </declare-styleable></resources>
2. Write in the layout file:
1<?xml version= "1.0" encoding= "Utf-8"?>2<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"3Xmlns:attrstest= "Http://schemas.android.com/apk/res/com.arlos.attrstest"4Android:layout_width= "Fill_parent"5android:layout_height= "Fill_parent"6android:orientation= "Vertical" >s7 8<Com.arlos.attrstest.MyTestView9Android:id= "@+id/tvtest"TenAndroid:layout_width= "Fill_parent" Oneandroid:layout_height= "Wrap_content" AAttrstest:name= "@string/myname" -android:gravity= "Top" -Attrstest:age= "Young" theAttrstest:textsize= "@dimen/aa" -android:text= "@string/hello"/> - -</LinearLayout>
View Code
Custom properties, resource file Attrs.xml