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

Android 3.0 Holo 主題全解析(API Level 11)

編輯:Android 開發實例

接續先前對 Theme 的整理,這篇把 API Level 11 新增的 Holo 系列樣式掃過一遍。測試環境是 3.0 模擬器,設定方式與先前相同:直接在 AndroidManifest.xml 的 activity 標籤上指定 android:theme。

Holo 是什麼

Holo(全像)是 Honeycomb 為平板帶來的全新視覺語言。官方原文的重點有三:

New Honeycomb holographic theme. Dark version. The widgets in the holographic theme are translucent on their background, so applications must ensure that any background they use with this theme is itself dark; otherwise, it will be difficult to see the widgets. The new UI style also includes a full action bar by default. Styles used by the Holo theme are named using the convention Type.Holo.Etc. (For example, Widget.Holo.Button, TextAppearance.Holo.Widget.PopupMenu.Large.) Specific resources used by Holo are named using the convention @type/foo_bar_baz_holo with trailing _dark or _light specifiers if they are not shared between both light and dark versions of the theme.

實務上必須牢記的是:Holo 的元件是半透明的,所以背景必須是深色,否則元件會看不清。另外它預設就帶一整條 Action Bar,命名規則則是 Type.Holo.Etc。

1. Theme_Holo 系列(深色)

Theme_Holo

Honeycomb 的全螢幕深色樣式,也是這一系列的地基。

Theme_Holo_Dialog

把 Activity 變成對話框。官方說明:對話框主題會讓視窗變成浮動式(不填滿整個螢幕),並在內容外圍加上框線;你可以把這個主題套在 Activity 上,讓它看起來像一個 Dialog。這是 targeting Honeycomb 以上版本的應用預設的 Dialog 主題。注意:若不自行指定大小,View 會顯示不全。

Theme_Holo_Dialog_MinWidth

同上,但為一般對話框設定了較合適的最小寬度。

Theme_Holo_DialogWhenLarge

視窗在小螢幕(small、normal)上以全螢幕顯示,在大螢幕(large、xlarge)上則以對話框形式顯示。

Theme_Holo_DialogWhenLarge_NoActionBar

同上,但沒有標題列(Action Bar)。

Theme_Holo_Dialog_NoActionBar

對話框樣式且不包含標題列,為預設狀態。同樣需要自行指定大小。

Theme_Holo_Dialog_NoActionBar_MinWidth

對話框樣式、無 Action Bar,並具備適合一般對話框的最小寬度。

Theme_Holo_InputMethod

現代 Holo 風格輸入法(IME)的預設主題,供 InputMethodService 使用。它繼承自 Theme.Panel,但另外設定了 IME 專用的動畫與若干自訂屬性。外觀近似 panel,需自訂大小否則顯示不全。

Theme_Holo_NoActionBar

深色 Holo 的變體,去掉 Action Bar。

Theme_Holo_NoActionBar_Fullscreen

深色 Holo 的變體,沒有標題列並填滿整個螢幕。(實測時這個與上一個的畫面幾乎相同,推測是模擬器上狀態列仍佔用空間所致,實際差異要到真機或全螢幕模式才明顯。)

Theme_Holo_Wallpaper

讓使用者選擇的桌布透出作為視窗背景。

Theme_Holo_Wallpaper_NoActionBar

同上,但沒有標題列。

Theme_Holo_Panel

把 Activity 變成一個「空矩形框」。它移除所有多餘的視窗裝飾、讓視窗浮動、背景透明,並關閉視窗後方的調暗效果。與 Dialog 主題的差別就在於完全沒有框線與任何樣式元素。需自訂大小否則顯示不全。

2. Theme_Holo_Light 系列(淺色)

結構與深色版一一對應,差別只在背景改為淺色:

New Honeycomb holographic theme. Light version. The widgets in the holographic theme are translucent on their background, so applications must ensure that any background they use with this theme is itself light; otherwise, it will be difficult to see the widgets. The new UI style also includes a full action bar by default.

  • Theme_Holo_Light:淺色全螢幕樣式,預設含完整 Action Bar。
  • Theme_Holo_Light_Dialog:淺色對話框樣式,浮動視窗加框線,需自訂大小。
  • Theme_Holo_Light_Dialog_MinWidth:具備合適最小寬度的淺色對話框。
  • Theme_Holo_Light_DialogWhenLarge:小螢幕全螢幕、大螢幕對話框。
  • Theme_Holo_Light_DialogWhenLarge_NoActionBar:同上但無 Action Bar。
  • Theme_Holo_Light_Dialog_NoActionBar:淺色對話框、無 Action Bar,需自訂大小。
  • Theme_Holo_Light_Dialog_NoActionBar_MinWidth:無 Action Bar 且具最小寬度。
  • Theme_Holo_Light_Panel:淺色的空白面板,移除所有視窗裝飾,需自訂大小。

3. 其他

Theme_NoTitleBar_OverlayActionModes

沒有標題列,但 Action Mode 的橫列會覆蓋在應用內容之上,而不是把內容往下推。
官方原文:No title bar, but Action Mode bars will overlay application content instead of pushing it down to make room.

Theme_WithActionBar

確保有 Action Bar 的主題。
官方原文:Default theme with an Action Bar.

總結

Honeycomb 的 Action Bar 相當於 Level 11 以下的 title bar,主要差別是 Action Bar 在對話框樣式下會多出一條橫線。選主題時的判斷順序其實很單純:先決定深淺(Holo 或 Holo_Light),再決定形態(全螢幕、Dialog、Panel、Wallpaper),最後決定要不要 Action Bar。

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