2012-07-19 94 views
18

我知道如何創建視圖自定義屬性,例如:如何將文檔添加到自定義屬性?

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name="SomeViewsCustomAttrs"> 
     <attr name="someAttr" format="dimension" /> 
     <attr name="anotherAttr" format="boolean" /> 
    </declare-styleable> 
</resources>  

我想知道如果有一種方法來添加文檔,這些自定義的attrs。在編輯XML編輯器中的佈局時,您可以獲取描述attrs的工具提示。例如,如果您正在鍵入android:layout_width=它會給你以下信息,「指定視圖的基本寬度。[尺寸,枚舉]」

有沒有辦法爲你自己的attrs提供?

感謝

+1

難道你有沒有找到答案呢? – drewhannay 2013-06-17 17:04:53

+0

@drewhannay我放棄了尋找,還沒有找到任何東西。 – cottonBallPaws 2013-06-18 16:23:38

回答

-1

你需要寫在代碼中的構造函數,然後將它們鏈接到XML。有關更多信息,請閱讀this

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name="SomeViewsCustomAttrs"> 
     <!-- Default highlight color for items that are pressed. --> 
     <attr name="colorPressedHighlight" format="color" /> 
     <!-- Default highlight color for items that are long-pressed. --> 
     <attr name="colorLongPressedHighlight" format="color" /> 
    </declare-styleable> 
</resources> 

並在Java文檔這樣您的視圖鏈接到屬性的Java源文件中(例如,從TextView):每個元素

3

添加XML註釋

* See {@link android.R.styleable#TextView TextView Attributes}, {@link android.R.styleable#View View Attributes} 
+3

我沒有關注你答案的第二部分(源文件)。 1)這是做什麼的,它爲什麼重要? 2)在Java源文件中,您將這些Java Doc註釋放在哪裏?(在包的頂部?在類/文件聲明中,在每種特定的方法?)? 3)爲什麼我會鏈接到'android.R.styleable'而不是'com.myproject.R.styleable'? – 2016-09-08 21:03:39

相關問題