Android上的Style分爲了兩個方面:
1,Theme是針對窗體級別的,改變窗體樣式;
2,Style是針對窗體元素級別的,改變指定控件或者Layout的樣式。
Android系統的themes.xml和style.xml(位於系統源代碼frameworks\base\core\res\res\values\)包含了很多系統定義好的style,建議在裏面挑個合適的,然後再繼承修改。
- 風格是一個包含一種或者多種格式化屬性的集合,你可以將其用爲一個單位用在佈局XML單個元素當中。比如,你可以定義一種風格來定義文本的字號大小和顏色,然後將其用在View元素的一個特定的實例。
- 主題是一個包含一種或者多種格式化屬性的集合,你可以將其爲一個單位用在應用中所有的Activity當中或者應用中的某個Activity當 中。比如,你可以定義一個主題,它爲window frame和panel 的前景和背景定義了一組顏色,併爲菜單定義可文字的大小和顏色屬性,你可以將這個主題應用在你程序當中所有的Activity裏。
<resources>
<style name="SpecialText" parent="@style/Text">
<item name="android:textSize">18sp</item>
<item name="android:textColor">#008</item>
</style>
</resources>
style="@style/SpecialText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World!" />
主題
<resources>
<style name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="windowFrame">@drawable/screen_frame</item>
<item name="windowBackground">@drawable/screen_background_white</item>
<item name="panelForegroundColor">#FF000000</item>
<item name="panelBackgroundColor">#FFFFFFFF</item>
<item name="panelTextColor">?panelForegroundColor</item>
<item name="panelTextSize">14</item>
<item name="menuItemTextColor">?panelTextColor</item>
<item name="menuItemTextSize">?panelTextSize</item>
</style>
</resources>
在manifest當中設置主題
<application android:theme="@style/CustomTheme">
<activity android:theme="@android:style/Theme.Dialog">
<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
在程序當中設置主題
super.onCreate(savedInstanceState);
...
setTheme(android.R.style.Theme_Light);
setContentView(R.layout.linear_layout_3);
}
下面的前三個之外直接複製就會出錯。@是說明系統已經定義過的,@android:style/ 是必須帶上的。
?android:theme="@android:style/Theme.Dialog" 將一個Activity顯示爲對話框模式
?android:theme="@android:style/Theme.NoTitleBar" 不顯示應用程序標題欄
?android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不顯示應用程序標題欄,並全屏
?android:theme="Theme.Light" 背景爲白色
?android:theme="Theme.Light.NoTitleBar" 白色背景並無標題欄
?android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,無標題欄,全屏
?android:theme="Theme.Black" 背景黑色
?android:theme="Theme.Black.NoTitleBar" 黑色背景並無標題欄
?android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,無標題欄,全屏
?android:theme="Theme.Wallpaper" 用系統桌面爲應用程序背景
?android:theme="Theme.Wallpaper.NoTitleBar" 用系統桌面爲應用程序背景,且無標題欄
?android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" 用系統桌面爲應用程序背景,無標題欄,全屏
?android:theme="Translucent"
?android:theme="Theme.Translucent.NoTitleBar" 半透明,無標題
?android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明,無標題,全屏
?android:theme="Theme.Panel" 面板風格顯示
?android:theme="Theme.Light.Panel" 平板風格顯示