應用界面主題Theme使用方法

主題Theme就是用來設置界面UI風格,可以設置整個應用或者某個活動Activity的界面風格。在Android SDK中內置了下面的Theme,可以按標題欄Title Bar和狀態欄Status Bar是否可見來分類:

 


  1. android:theme="@android:style/Theme.Dialog"   將一個Activity顯示爲能話框模式  
  2. android:theme="@android:style/Theme.NoTitleBar"  不顯示應用程序標題欄  
  3. android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  不顯示應用程序標題欄,並全屏  
  4. android:theme="Theme.Light"  背景爲白色  
  5. android:theme="Theme.Light.NoTitleBar"  白色背景並無標題欄   
  6. android:theme="Theme.Light.NoTitleBar.Fullscreen"  白色背景,無標題欄,全屏  
  7. android:theme="Theme.Black"  背景黑色  
  8. android:theme="Theme.Black.NoTitleBar"  黑色背景並無標題欄  
  9. android:theme="Theme.Black.NoTitleBar.Fullscreen"    黑色背景,無標題欄,全屏  
  10. android:theme="Theme.Wallpaper"  用系統桌面爲應用程序背景  
  11. android:theme="Theme.Wallpaper.NoTitleBar"  用系統桌面爲應用程序背景,且無標題欄  
  12. android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen"  用系統桌面爲應用程序背景,無標題欄,全屏  
  13. android:theme="Translucent"  半透明  
  14. android:theme="Theme.Translucent.NoTitleBar" 半透明、無標題欄  
  15. android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明、無標題欄、全屏  
  16. android:theme="Theme.Panel"  
  17. android:theme="Theme.Light.Panel"  




這些主題可以應用到整個應用Application範圍或者某個活動Activity範圍中。

應用Application範圍
在AndroidManifest.xml中的application節點中設置theme屬性,主題theme應用到整個應用程序中。
<application
    Android:icon=”@drawable/icon”
    Android:icon=”@string/app_name”
    Android:icon=”@android:style/ Theme.Black.NoTitleBar”>

活動Activity範圍
使用java代碼或者在AndroidManifest.xml中對活動Activity的主題進行設置,主題僅應用到當前活動中。
在AndroidMainifest.xml設置方法:
<activity
android:name=“.About”
android:label=“@string/app_name”
android:theme=“@android:style/ Theme.Black.NoTitleBar” >

使用java代碼進行設置,在當前活動Activity的onCreate中進行設置:
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Translucent_NoTitleBar);
setContentView(R.layout.main);
}

發佈了136 篇原創文章 · 獲贊 4 · 訪問量 26萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章