1. 程式人生 > >Android去Title和主題Theme使用方法

Android去Title和主題Theme使用方法

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

去除Title有兩種方式:
方法一:可以在AndroidManifest.xml中作如下配置,這樣就沒有標題欄了
<application android:theme="@style/Theme.AppCompat.Light.NoActionBar">
方法二:在當前activity中寫如下程式碼
requestWindowFeature(Window.FEATURE_NO_TITLE);