此页面上的内容需要较新版本的 Adobe Flash Player。

获取 Adobe Flash Player

您现在的位置: 智可网 - 程序开发 - Android开发 - android高级开发 - 正文
Android基础教程之-------Android中两种设置全屏的方法
教程录入:admin    责任编辑:quan 作者:佚名 文章来源:weizhulin.blog.51cto
在开发中我们经常需要把我们的应用设置为全屏,这里我所知道的有俩中方法,一中是在代码中设置,另一种方法是在配置文件里改!
一、在代码中设置:
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>     
 
在这里我还想说明一下,用前者在我们应用运行后,会看到短暂的状态栏,然后才全屏,而第二种方法是不会有这种情况的,所以我建议
大家使用后者! 谢谢~
分享
打赏我
打开支付宝"扫一扫" 打开微信"扫一扫"
客户端
"扫一扫"下载智可网App
意见反馈
Android基础教程之-------Android中两种设置全屏的方法
作者:佚名 来源:weizhulin.blog.51cto
在开发中我们经常需要把我们的应用设置为全屏,这里我所知道的有俩中方法,一中是在代码中设置,另一种方法是在配置文件里改!
一、在代码中设置:
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>     
 
在这里我还想说明一下,用前者在我们应用运行后,会看到短暂的状态栏,然后才全屏,而第二种方法是不会有这种情况的,所以我建议
大家使用后者! 谢谢~