2012-02-20 51 views
1

在HTML/CSS中,您可以通過在CSS中定義p來覆蓋所有段落覆蓋所有表單元素樣式,如HTML + CSS

即, p { color: blue; }

你可以在Android中使用mimc嗎?我想爲styles.xml中的所有表單元素定義一組樣式,然後我編寫的每個佈局都將使用這些屬性。

目前,我必須指定在佈局風格:即

<EditText android:id="@+id/address1" style="@style/EditText" />

這似乎有點多餘(且容易出錯)。

感謝,

約翰

回答

2

你必須創建一個XML 文件定義你想要的樣式,並將其存儲在RES /值文件夾中。

<?xml version="1.0" encoding="utf-8"?> 
<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> 

這是風格的一個例子,一旦你有你的風格。你可以做這樣的事情就applay到每一個觀點:

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

這個例子是:

http://developer.android.com/guide/topics/ui/themes.html

+0

謝謝!所以聲明自定義名稱我可以複製CSS在做什麼類? – porjolovsky 2017-02-05 23:38:05