Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 開發實例

Android 內建 Theme 完整整理(API Level 11 以下)

編輯:Android 開發實例

這篇把 API 文件中 style 底下的 theme 全部實測一遍。為了涵蓋不同版本,Level 11 以上用 3.0 模擬器,Level 11 以下則用 2.3.3(Nexus One)的環境。設定方式統一是在 AndroidManifest.xml 中,透過 activity 標籤的 android:theme 屬性指定。

1. 預設系列

Theme

系統預設主題,也就是當 activity 沒有明確指定 theme 時所採用的樣式。

The default system theme. This is the theme used for activities that have not explicitly set their own theme.
You can count on this being a dark background with light text on top, but should try to make no other assumptions about its appearance. In particular, the text inside of widgets using this theme may be completely different, with the widget container being a light color and the text on top of it a dark color.

重點在最後一句:不要對元件的外觀做任何過多假設。你能確定的只有「深色背景配淺色文字」這件事,元件容器本身可能是淺底深字。

Theme_NoDisplay

什麼都不顯示。適合那些只是執行一段邏輯、在 resume 之前就自己 finish 掉的 Activity。

Default theme for activities that don't actually display a UI; that is, they finish themselves before being resumed.

Theme_NoTitleBar

預設(深色)主題的變體,去掉標題列。
原文:Variant of the default (dark) theme with no title bar

Theme_NoTitleBar_Fullscreen

預設主題的變體,沒有標題列且填滿整個螢幕。
原文:Variant of the default (dark) theme that has no title bar and fills the entire screen

2. 純黑系列

Theme_Black

Special variation on the default theme that ensures the background is completely black. This is useful for things like image viewers and media players. If you want the normal (dark background) theme do not use this, use Theme.

它保證背景是「真正的全黑」,適合圖片檢視器、媒體播放器這類需要純黑底襯托內容的場景。若只是想要一般的深色主題,應該用 Theme 而不是這個。

Theme_Black_NoTitleBar

黑底主題去掉標題列。
原文:Variant of the black theme with no title bar

Theme_Black_NoTitleBar_Fullscreen

黑底、無標題列、全螢幕。
原文:Variant of the black theme that has no title bar and fills the entire screen

3. 淺色系列

Theme_Light

Theme for a light background with dark text on top. Set your activity to this theme if you would like such an appearance. As with the default theme, you should try to assume little more than that the background will be a light color.

淺底深字,與 Theme_Black 剛好相反。同樣地,除了「背景是淺色」之外不要多做假設。

Theme_Light_NoTitleBar

淺底、無標題列。
原文:Variant of the light theme with no title bar

Theme_Light_NoTitleBar_Fullscreen

淺底、無標題列、全螢幕。
原文:Variant of the light theme that has no title bar and fills the entire screen

4. 對話框與面板

Theme_Dialog

Default theme for dialog windows and activities, which is used by the Dialog class. This changes the window to be floating (not fill the entire screen), and puts a frame around its contents. You can set this theme on an activity if you would like to make an activity that looks like a Dialog.

整個 Activity 會以浮動視窗的形式出現,內容外圍有框線。實測必須自行指定大小,否則內容會顯示不全。

Theme_Panel

Default dark theme for panel windows. This removes all extraneous window decorations, so you basically have an empty rectangle in which to place your content. It makes the window floating, with a transparent background, and turns off dimming behind the window.

相當於把 Dialog 的所有元素都拿掉,只剩一個空的矩形框,且視窗浮動、背景透明、 disable 掉背後的調暗效果。需自訂大小否則顯示不全。

Theme_Light_Panel

面板主題的淺色版本,其餘行為與 Theme_Panel 相同。需自訂大小。

Theme_InputMethod

供輸入法使用的面板式主題。

5. 桌布系列

Theme_Wallpaper

Default theme for windows that want to have the user's selected wallpaper appear behind them.

讓使用者挑選的桌布透出來當背景。

Theme_WallpaperSettings

Theme for a wallpaper's setting activity that is designed to be on top of a dark background.

專供桌布的設定畫面使用,設計前提是它會疊在深色背景之上。(實測時發現畫面上變暗的是前一層介面而非桌布本身,這點值得留意。)

Theme_Light_WallpaperSettings

同上,但設計前提是疊在淺色背景之上。

Theme_Wallpaper_NoTitleBar

桌布背景、無標題列。
原文:Variant of the translucent theme with no title bar

Theme_Wallpaper_NoTitleBar_Fullscreen

桌布背景、無標題列、全螢幕。
原文:Variant of the translucent theme that has no title bar and fills the entire screen

6. 半透明系列

Theme_Translucent

Default theme for translucent activities, that is windows that allow you to see through them to the windows behind. This sets up the translucent flag and appropriate animations for your windows.

會把啟動這個 Activity 之前的畫面保留下來、以半透明方式呈現在背後,並套用對應的轉場動畫。適合做浮層式的操作介面。

Theme_Translucent_NoTitleBar

半透明、無標題列。
原文:Variant of the translucent theme with no title bar

Theme_Translucent_NoTitleBar_Fullscreen

半透明、無標題列、全螢幕。
原文:Variant of the translucent theme that has no title bar and fills the entire screen

選主題的實務建議

這些主題其實可以沿著三個維度來拆解:底色(預設深色/Black 純黑/Light 淺色)、視窗形態(正常、Dialog 浮動框線、Panel 空白矩形、Translucent 半透明、Wallpaper 桌布透出)、裝飾(要不要標題列、要不要全螢幕)。看懂這個結構之後,遇到沒見過的組合名稱也能推測出它的行為。

另外提醒兩點:使用 Dialog 與 Panel 系列時務必自行處理視窗尺寸,否則內容會被裁切;而 Theme 系列對元件外觀不做保證,因此版面不要假設元件一定是深底或淺底,該指定的顏色還是要自己指定。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved