styleable 屬性 說明


 屬性一般定義在 values/attrs.xml  下,如:

<declare-styleable name="window">

<attr name="windowBackground"/>

<attr name="windowNoTitle" />

.....

 </declare-styleable>

styleable 在 R.java 中生成了一個int[] 數組,數組的內容是 styleable 屬性包含的attr 對應的id 值;


 如:

 定義 

 <declare-styleable name="mystyle">
       <attr name="textColor" format="dimension" />
       <attr name="textSize" format="dimension" />
   </declare-styleable>  
   
 <declare-styleable name="orientaion">
  <attr name="orientation>
   < enum name="horizontal“ value="0"/>
   <enum  name="vertical" value="1" />
  </attr>
</declare-styleable>  
 

format 類型說明:

reference //引用

color  //顏色

dimension //尺寸

float  //浮點值

integer //

string //字符串

fraction // 百分數

枚舉型

flag 


 
使用:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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> 

< attr name="windowSoftInputMode">
  < flag name = "stateUnspecified" value = "0" />
  < flag name = "stateUnchanged" value = "1" />
  < flag name = "stateHidden" value = "2" />
 < /attr>

xml 中使用:
android:windowSoftInputMode = "stateUnspecified | stateUnchanged | stateHidden">


這種屬性定義一般用於自定義控件。
notice: mystyle 名字不固定;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章