Android:theme的學習使用

    android:theme="@android:style/Theme.Dialog"   將一個Activity顯示爲能話框模式  
    android:theme="@android:style/Theme.NoTitleBar"  不顯示應用程序標題欄  
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  不顯示應用程序標題欄,並全屏  
    android:theme="Theme.Light"  背景爲白色  
    android:theme="Theme.Light.NoTitleBar"  白色背景並無標題欄   
    android:theme="Theme.Light.NoTitleBar.Fullscreen"  白色背景,無標題欄,全屏  
    android:theme="Theme.Black"  背景黑色  
    android:theme="Theme.Black.NoTitleBar"  黑色背景並無標題欄  
    android:theme="Theme.Black.NoTitleBar.Fullscreen"    黑色背景,無標題欄,全屏  
    android:theme="Theme.Wallpaper"  用系統桌面爲應用程序背景  
    android:theme="Theme.Wallpaper.NoTitleBar"  用系統桌面爲應用程序背景,且無標題欄  
    android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen"  用系統桌面爲應用程序背景,無標題欄,全屏  
    android:theme="Translucent"  半透明  
    android:theme="Theme.Translucent.NoTitleBar" 半透明、無標題欄  
    android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明、無標題欄、全屏  
    android:theme="Theme.Panel"  
    android:theme="Theme.Light.Panel"  


1.Android:theme類型
      
   主題Theme就是用來設置界面UI風格,可以設置整個應用或者某個活動Activity的界面風格。


2.如何應用??

這些主題可以應用到整個應用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);
}

3.例子

這裏我是統一將theme寫在AndroidManifest.xml中定義,如下圖:

image

先總結level爲11以下的theme:

1、Theme:

它的意思爲默認狀態,即如果theme這裏不填任何屬性的時候,默認爲Theme。

api原文爲:

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 

1.1Theme_NoDisplay

它的意思爲任何都不顯示。比較適用於只是運行了activity,但未顯示任何東西。

api原文如下:

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

效果圖如下:

Theme_NoDisplay

1.2、Theme_NoTitleBar

意思爲:背景主題的沒有標題欄的樣式,默認如果沒有設置的話,顯示黑背景

api原文:

Variant of the default (dark) theme with no title bar

效果圖如下:

Theme_NoTitleBar

1.3、Theme_NoTitleBar_Fullscreen

意思爲:背景主題的沒有標題欄且全屏的樣式,默認爲黑背景

api原文:

Variant of the default (dark) theme that has no title bar and fills the entire screen

效果圖如下:

Theme_NoTitleBar_Fullscreen

2、Theme_Black:

它的意思爲默認狀態下黑背景。

api原文如下:

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 donot use this, useTheme.

效果圖如下:

Theme_Black 

2.1、Theme_Black_NoTitleBar:

意思爲:黑背景主題的沒有標題欄的樣式

api原文:

Variant of the black theme with no title bar

效果圖如下:

Theme_Black_NoTitleBar

2.2、Theme_Black_NoTitleBar_Fullscreen

意思爲:黑背景主題的沒有標題欄且全屏的樣式

api原文:

Variant of the black theme that has no title bar and fills the entire screen

效果圖如下:

Theme_Black_NoTitleBar_Fullscreen

3、Theme_Light

意思爲:默認狀態下亮背景,與上述黑背景Theme_Black相反。

api原文:

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_Light

3.1、Theme_Light_NoTitleBar

意思爲:亮背景主題的沒有標題欄的樣式,與Theme_Black_NoTitleBar相反

api原文:

Variant of the light theme with no title bar

效果圖如下:

Theme_Light_NoTitleBar

3.2、Theme_Light_NoTitleBar_Fullscreen

意思爲:亮背景主題的沒有標題欄且全屏顯示的樣式,與Theme_Black_NoTitleBa_Fullscreenr相反

api原文:

Variant of the light theme that has no title bar and fills the entire screen

效果圖如下:

Theme_Light_NoTitleBar_Fullscreen 

4、Theme_Dialog

意思爲:對話框樣式 將整個activity變成對話框樣式出現。

api原文:

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.

效果圖如下:這裏需要自定義大小,否則顯示不全。

Theme_Dialog

5、Theme_InputMethod

6、Theme_Panel

意思爲:刪除掉所有多餘的窗口裝飾,在一個空的矩形框中填充內容,作用範圍相當於把dialog中的所有元素全部去掉,只是一個空的矩形框,且此爲默認的樣式。

api原文:

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.

效果圖如下:這裏需要自定義大小,否則顯示不全。

Theme_Panel

6.1、Theme_Light_Panel

意思爲:刪除掉所有多餘的窗口裝飾,在一個空的矩形框中填充內容,作用範圍相當於把dialog中的所有元素全部去掉,只是一個空的矩形框,且默認是light的樣式。

api原文:

Default light 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.

效果圖如下:這裏需要自定義大小,否則顯示不全。

Theme_Light_Panel 

7、

Theme_Wallpaper

意思爲:使用牆紙做主題,默認狀態。

api原文:

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

效果圖如下:

Theme_Wallpaper

7.1、Theme_WallpaperSettings

意思爲:使用牆紙做主題,默認是使用將上一個界面調暗之後作爲主題,(這裏我很疑惑爲什麼是上一個界面變暗而不是牆紙主題變暗呢?)

api原文:

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

效果圖如下:

Theme_WallpaperSettings

7.2、Theme_Light_WallpaperSettings

意思爲:使用牆紙做主題,默認Light狀態。

api原文:

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

效果圖如下:

Theme_Light_WallpaperSettings

7.3、Theme_Wallpaper_NoTitleBar

意思爲:使用牆紙做主題,且沒有標題欄

api原文:

Variant of the translucent theme with no title bar

效果圖如下:

Theme_Wallpaper_NoTitleBar

7.4、Theme_Wallpaper_NoTitleBar_Fullscreen

意思爲:使用牆紙做主題,且沒有標題欄,且全屏顯示

api原文:

Variant of the translucent theme that has no title bar and fills the entire screen

效果圖如下:

Theme_Wallpaper_NoTitleBar_Fullscreen

8、Theme_Translucent

意思爲:半透明狀態下的背景,將運行此activity之前的屏幕作爲半透明狀態作爲此activity運行時的樣式。

api原文:

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.

效果圖如下:

Theme_Translucent

8.1、Theme_Translucent_NoTitleBar

意思爲:半透明狀態下沒有標題欄的背景,將運行此activity之前的屏幕作爲半透明狀態作爲此activity運行時的樣式。

api原文:

Variant of the translucent theme with no title bar

效果圖如下:

Theme_Translucent_NoTitleBar

8.2、Theme_Translucent_NoTitleBar_Fullscreen

意思爲:半透明狀態下沒有標題欄且全屏的背景,將運行此activity之前的屏幕作爲半透明狀態作爲此activity運行時的樣式。

api原文:

Variant of the translucent theme that has no title bar and fills the entire screen

效果圖如下:

Theme_Translucent_NoTitleBar_Fullscreen

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