Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 高級開發 >> Android基礎教程之-------Android中兩種設置全屏的方法

Android基礎教程之-------Android中兩種設置全屏的方法

編輯:高級開發

在開發中我們經常需要把我們的應用設置為全屏,這裡我所知道的有倆中方法,一中是在代碼中設置,另一種方法是在配置文件裡改! 一、在代碼中設置: vIEw plaincopy to clipboardprint? 
package com.android.tutor;        
import android.app.Activity;        
import android.os.Bundle;        
import android.vIEw.Window;        
import android.vIEw.WindowManager;        
public class OpenGl_Lesson1 extends Activity {        
        public void onCreate(Bundle savedInstanceState) {        
                super.onCreate(savedInstanceState);        
             //無title            
             requestWindowFeature(Window.FEATURE_NO_TITLE);            
                //全屏            
             getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,                
                                            WindowManager.LayoutParams. FLAG_FULLSCREEN);         
                         
                setContentVIEw(R.layout.main);        
        }        
}     
package com.android.tutor; 
import android.app.Activity; 
import android.os.Bundle; 
import android.vIEw.Window; 
import android.vIEw.WindowManager; 
public class OpenGl_Lesson1 extends Activity { 
        public void onCreate(Bundle savedInstanceState) { 
                super.onCreate(savedInstanceState); 
             //無title     
             requestWindowFeature(Window.FEATURE_NO_TITLE);     
                //全屏     
             getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,         
                                            WindowManager.LayoutParams. FLAG_FULLSCREEN);    
                    
                setContentVIEw(R.layout.main); 
        } 
}    
 
在這裡要強調一點,設置全屏的倆段代碼必須在setContentVIEw(R.layout.main) 之前,不然會報錯。 二、在配置文件裡修改 (android:theme="@android:style/Theme.NoTitleBar.Fullscreen"): 
 
vIEw plaincopy to clipboardprint? 
<?XML version="1.0" encoding="utf-8"?>        
<manifest XMLns:android="http://schemas.android.com/apk/res/android"     
            package="com.android.tutor"     
            android:versionCode="1"     
            android:versionName="1.0">        
        <application android:icon="@drawable/icon" android:label="@string/app_name">        
                <activity android:name=".OpenGl_Lesson1"     
                                    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>        
        <uses-sdk android:minSdkVersion="7" />        
</manifest>        
<?XML version="1.0" encoding="utf-8"?> 
<manifest XMLns:android="http://schemas.android.com/apk/res/android" 
            package="com.android.tutor" 
            android:versionCode="1" 
            android:versionName="1.0"
        <application android:icon="@drawable/icon" android:label="@string/app_name"
                <activity android:name=".OpenGl_Lesson1" 
                        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> 
        <uses-sdk android:minSdkVersion="7" /> 
</manifest>     
 
在這裡我還想說明一下,用前者在我們應用運行後,會看到短暫的狀態欄,然後才全屏,而第二種方法是不會有這種情況的,所以我建議 大家使用後者! 謝謝~
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved