標籤:
在開發android的應用當中,我們會遇到將一些介面設定為全螢幕顯示的格式,有兩種實現的方法。其一是在Java代碼中實現,其二是在設定檔中實現。
1. 在Java代碼中設定
super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); //無title getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //全屏 setContentView(R.layout.main);
在這裡需要注意的是這兩段Java代碼必須放在setContentView( ); 之前,不然會報錯,錯誤顯示如下。
01-14 05:25:41.429: E/AndroidRuntime(7405): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
2. 在Manifest檔案中修改
在預設啟動的Activity裡添加 android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 即可
<activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
Android中介面實現全螢幕顯示的兩種方式