天天看點

Android應用設定全屏的方法第一種是代碼實作第二種是在AndroidManifest,xml清單配置檔案裡配置第三種方法是自定義全屏Theme

一般在設定Android應用全屏顯示有三種方法

第一種是代碼實作

protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//設定無Title
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		//設定應用全屏,必須寫在setContentView方法前面!!!記得!
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_main);
           

第二種是在AndroidManifest,xml清單配置檔案裡配置

在相應的Activity中節點中添加屬性:android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 即可以設定某個Activity全屏顯示。若設定成 android:theme="@android:style/Theme.NoTitleBar" 即是隻是設定成無标題狀态。

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.expandablelistview.MainActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
           

第三種方法是自定義全屏Theme

在style.xml檔案中定義theme(如果沒有style.xml,在res/values目錄下建立)

<resources> 
    <style name="Theme.NoTitle_FullScreen"> 
        <item name="android:windowNoTitle">true</item>    
        <item name="android:windowFullscreen">true</item>      
    </style> 
</resources>
           

然後直接在AndroidManifest.xml中需要全屏顯示的Activity屬性中添加

android:theme="@style/Theme.NoTitle_FullScree"

繼續閱讀