編輯:Android 開發實例
接續先前對 Theme 的整理,這篇把 API Level 11 新增的 Holo 系列樣式掃過一遍。測試環境是 3.0 模擬器,設定方式與先前相同:直接在 AndroidManifest.xml 的 activity 標籤上指定 android:theme。
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。
Honeycomb 的全螢幕深色樣式,也是這一系列的地基。
把 Activity 變成對話框。官方說明:對話框主題會讓視窗變成浮動式(不填滿整個螢幕),並在內容外圍加上框線;你可以把這個主題套在 Activity 上,讓它看起來像一個 Dialog。這是 targeting Honeycomb 以上版本的應用預設的 Dialog 主題。注意:若不自行指定大小,View 會顯示不全。
同上,但為一般對話框設定了較合適的最小寬度。
視窗在小螢幕(small、normal)上以全螢幕顯示,在大螢幕(large、xlarge)上則以對話框形式顯示。
同上,但沒有標題列(Action Bar)。
對話框樣式且不包含標題列,為預設狀態。同樣需要自行指定大小。
對話框樣式、無 Action Bar,並具備適合一般對話框的最小寬度。
現代 Holo 風格輸入法(IME)的預設主題,供 InputMethodService 使用。它繼承自 Theme.Panel,但另外設定了 IME 專用的動畫與若干自訂屬性。外觀近似 panel,需自訂大小否則顯示不全。
深色 Holo 的變體,去掉 Action Bar。
深色 Holo 的變體,沒有標題列並填滿整個螢幕。(實測時這個與上一個的畫面幾乎相同,推測是模擬器上狀態列仍佔用空間所致,實際差異要到真機或全螢幕模式才明顯。)
讓使用者選擇的桌布透出作為視窗背景。
同上,但沒有標題列。
把 Activity 變成一個「空矩形框」。它移除所有多餘的視窗裝飾、讓視窗浮動、背景透明,並關閉視窗後方的調暗效果。與 Dialog 主題的差別就在於完全沒有框線與任何樣式元素。需自訂大小否則顯示不全。
結構與深色版一一對應,差別只在背景改為淺色:
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.
沒有標題列,但 Action Mode 的橫列會覆蓋在應用內容之上,而不是把內容往下推。
官方原文:No title bar, but Action Mode bars will overlay application content instead of pushing it down to make room.
確保有 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。
Android 登入介面開發指南:從 XML 版面到鎖定機制
登入畫面通常是一個 App 使用者最先接觸到的部分。無論背後接的是 Facebook、微博還是自建服務,它的責任都一样:收進帳號密碼、驗證、決定放行或退回。本章說明如何打
Android JSON 解析實戰:用 JSONObject 取出你要的欄位
JSON 的全名是 JavaScript Object Notation(JavaScript 物件符號法),它是一種與程式語言無關的輕量級資料交換格式。語法乾淨、可讀性
Android Service 完全解析:生命週期與 start/bind 的差別
前面談過 Activity 與 Intent,這次來看 Service。一句話概括:如果把 Activity 比喻成前台程式,Service 就是背景程式,整個生命週期都
Android Fragment 雙欄布局實例解析
Fragment 的雙欄概念 Fragment 是 Android 3.0 之後引入的介面元件,適合將畫面拆成可重複使用的區塊。常見用法是左側顯示列表,右側顯示內容;在平