歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android自定義屬性之format介紹

Android自定義屬性之format介紹

日期:2017/3/1 10:21:09   编辑:Linux編程

我們在做項目的時候,由於Android自帶的屬性不能滿足需求,android提供了自定義屬性的方法,其中的format是做什麼用的?以及如何使用它?下面列出一些常用的。

1. reference:參考某一資源ID。

(1)屬性定義:

<declare-styleable name = "名稱">

<attr name = "background" format = "reference" />

</declare-styleable>

(2)屬性使用:

<ImageView

android:layout_width = "42dip"
android:layout_height = "42dip"
android:background = "@drawable/圖片ID"

/>

2. color:顏色值。

(1)屬性定義:

<declare-styleable name = "名稱">

<attr name = "textColor" format = "color" />

</declare-styleable>

(2)屬性使用:

<TextView

android:layout_width = "42dip"
android:layout_height = "42dip"
android:textColor = "#00FF00"

/>

3. boolean:布爾值。

(1)屬性定義:

<declare-styleable name = "名稱">

<attr name = "focusable" format = "boolean" />

</declare-styleable>

(2)屬性使用:

<Button

android:layout_width = "42dip"
android:layout_height = "42dip"

android:focusable = "true"

/>

4. dimension:尺寸值。

(1)屬性定義:

<declare-styleable name = "名稱">

<attr name = "layout_width" format = "dimension" />

</declare-styleable>

(2)屬性使用:

<Button

android:layout_width = "42dip"
android:layout_height = "42dip"

/>

Copyright © Linux教程網 All Rights Reserved