Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 常用 Theme 樣式速查表

編輯:關於 Android 程式設計

開發時常需要快速切換 Activity 的外觀風格,而這些多半只要一行 android:theme 就能搞定。以下把平台內建的樣式整理成對照清單,寫在清單檔的 <activity> 節點上即可。

// 把 Activity 變成對話框外觀
android:theme="@android:style/Theme.Dialog"

// 隱藏標題列
android:theme="@android:style/Theme.NoTitleBar"

// 隱藏標題列並全螢幕
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

// 白色背景
android:theme="@android:style/Theme.Light"

// 白色背景、無標題列
android:theme="@android:style/Theme.Light.NoTitleBar"

// 白色背景、無標題列、全螢幕
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"

// 黑色背景
android:theme="@android:style/Theme.Black"

// 黑色背景、無標題列
android:theme="@android:style/Theme.Black.NoTitleBar"

// 黑色背景、無標題列、全螢幕
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

// 以系統桌布作為應用背景
android:theme="@android:style/Theme.Wallpaper"

// 系統桌布背景、無標題列
android:theme="@android:style/Theme.Wallpaper.NoTitleBar"

// 系統桌布背景、無標題列、全螢幕
android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"

// 半透明效果
android:theme="@android:style/Theme.Translucent"

// 半透明、無標題列
android:theme="@android:style/Theme.Translucent.NoTitleBar"

// 半透明、無標題列、全螢幕
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"

用法示例:

<activity
    android:name=".SplashActivity"
    android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" />

從 Android 5.0 起 Material Design 成為預設,Theme.Light 這類舊樣式雖仍可用,但建議改用 Theme.AppCompat.Light.NoActionBar 等 AppCompat 版本,才能在各版本上維持一致的外觀並正確套用 ActionBar 與 Material 元件。

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