在進行android開發時,每個Activity會預設帶上一個title bar用以顯示程式名,有時為了擴大螢幕的顯示地區需要去掉這個title bar,去掉螢幕上的title bar有3個方法,
第一個方法是在代碼去掉title bar
在Activity的onCreate中加入如下代碼:
Java代碼
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
但是使用這種方法,是在Activity將要顯示的時候,仍然會出現title bar,然後再將其去掉,使用者體驗不好。
第二種方法是使用style設定檔,步驟如下:
1.在res/values檔案夾下建立一個xml檔案,名為mainStyle.xml,內容如下:
Java代碼
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <style name="NoTitle" parent="android:Theme">
- <item name="android:windowNoTitle">true</item>
- </style>
- </resources>
<?xml version="1.0" encoding="utf-8"?><resources> <style name="NoTitle" parent="android:Theme"> <item name="android:windowNoTitle">true</item> </style></resources>
2.然後在AndroidManifest.xml中需要去掉title bar的activities的節點上加上一個樣式屬性,代碼如下:
Java代碼
- <activity android:name=".view.AutoTaskDemo" android:label="@string/app_name"
- android:configChanges="keyboardHidden|orientation|locale" android:theme="@style/NoTitle">
<activity android:name=".view.AutoTaskDemo" android:label="@string/app_name"android:configChanges="keyboardHidden|orientation|locale" android:theme="@style/NoTitle">
第三種方法是直接在AndroidManifest.xml中進行修改,
把需要去掉title bar的activities的節點上加上一個樣式屬性,代碼如下:
Java代碼
- <activity android:name=".view.SettingActivity"
- android:configChanges="keyboardHidden|orientation" android:theme="@android:style/Theme.NoTitleBar"/>
<activity android:name=".view.SettingActivity"android:configChanges="keyboardHidden|orientation" android:theme="@android:style/Theme.NoTitleBar"/>
也可以在AndroidManifest.xml檔案的application節點上修改,對所有的activity都有效,代碼如下:
Java代碼
- <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">