2012-10-16 27 views
0

我在Layout XML中定義了標題和基本TextView。我在整個應用程序中經常使用這些元素。到目前爲止,我只是複製並粘貼了每個TextView,但我想必須有一種方法來創建類似於CSS中的「類」,我可以定義與標題元素相同的屬性的切割集。Android SDK - 爲不同視圖元素的相同屬性創建「類」

任何想法如何將它們存儲到類或其他東西?

+1

你想要的類AttributeSet中。每個視圖都有三個默認構造函數中的兩個。 – Shark

+0

款式可能?或者包括 – njzk2

+0

。這也可以工作 – njzk2

回答

2

聽起來像你正在尋找styles

TextView的實施

<TextView 
    style="@style/CodeFont" 
    android:text="@string/hello" /> 

RES /價值/ styles.xml

<resources> 
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium"> 
     <item name="android:layout_width">fill_parent</item> 
     <item name="android:layout_height">wrap_content</item> 
     <item name="android:textColor">#00FF00</item> 
     <item name="android:typeface">monospace</item> 
    </style> 
</resources> 
+0

謝謝,正是我在找的! – Ron

相關問題