新手學習之作,本文章參考http://android.blog.51cto.com/268543/636134
本文解決activity全屏顯示問題
去掉屏幕上的title bar有3個方法:
1. Java代碼實現
@Override publicvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); //... }
留意這語句所在的位置的,似乎所有requestWindowFeature的操作都要放在setContentView的前面。
但使用這種方法,用戶體驗不太好,在Activity將要顯示時,仍然會出現title bar,然後再去掉的。
2. 自定義style配置文件
在\res\values裏面的style.xml添加:
<resources> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> <style name="AppTheme.NoTitleBar" parent="AppBaseTheme"> <item name="android:windowNoTitle">true</item> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> </resources>
這裏應該注意,改的最好是Application theme
然後在AndroidManifest.xml文件裏,給需要去掉title bar的activity的節點上加上android:theme="@style/NoTitle,代碼如下:
<activity android:name=".MainActivity" android:configChanges="orientation|keyboardHidden" android:theme="@style/AppTheme.NoTitleBar"/> ...
3. 直接在AndroidManifest.xml中進行修改
原來我們可以無需自定義style配置的,直接調用系統的就行了:
<activity android:name=".MainActivity" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.NoTitleBar"/> ...
如果我們要設置整個Application都去掉title bar,那麼就設置application:
<application android:icon="@drawable/lightbulb"android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar"> ...
title bar還能夠自定義的,請查看文章《自定義Activity標題欄(Title bar)》http://android.blog.51cto.com/268543/636134