屬性一般定義在 values/attrs.xml 下,如:
<declare-styleable name="window">
<attr name="windowBackground"/>
<attr name="windowNoTitle" />
.....
</declare-styleable>
styleable 在 R.java 中生成了一個int[] 數組,數組的內容是 styleable 屬性包含的attr 對應的id 值;
如:
定義
<attr name="textColor" format="dimension" />
<attr name="textSize" format="dimension" />
</declare-styleable>
reference //引用color //顏色dimension //尺寸float //浮點值integer //string //字符串fraction // 百分數枚舉型flag
xmlns:tools="http://schemas.android.com/tools"
xmlns:mystyle="http://schemas.android.com/apk/res/com.example.teststyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.teststyle.MainActivity" >
<com.example.teststyle.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
mystyle:textSize = "@dimen/mydimen"/>
</RelativeLayout>
< flag name = "stateUnspecified" value = "0" />
< flag name = "stateUnchanged" value = "1" />
< flag name = "stateHidden" value = "2" />
< /attr>