无网不进  
软硬件开发

Android中两种设置全屏的方法

 

在开发中我们经常需要把我们的应用设置为全屏,这里我所知道的有俩中方法,一中是在代码中设置,另一种方法是在配置文件里改!

 一、在代码中设置:

 1 package com.android.tutor;
 2 import android.app.Activity;
 3 import android.os.Bundle;
 4 import android.view.Window;
 5 import android.view.WindowManager;
 6 public class OpenGl_Lesson1 extends Activity {
 7     public void onCreate(Bundle savedInstanceState) {
 8         super.onCreate(savedInstanceState);
 9        //无title  
10        requestWindowFeature(Window.FEATURE_NO_TITLE);  
11         //全屏  
12        getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,    
13                       WindowManager.LayoutParams. FLAG_FULLSCREEN); 
14          
15         setContentView(R.layout.main);
16     }
17 }

在这里要强调一点,设置全屏的俩段代码必须在setContentView(R.layout.main) 之前,不然会报错。

 

二、在配置文件里修改(android:theme="@android:style/Theme.NoTitleBar.Fullscreen"):

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 3       package="com.android.tutor"
 4       android:versionCode="1"
 5       android:versionName="1.0">
 6     <application android:icon="@drawable/icon" android:label="@string/app_name">
 7         <activity android:name=".OpenGl_Lesson1"
 8                   android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
 9                   android:label="@string/app_name">
10             <intent-filter>
11                 <action android:name="android.intent.action.MAIN" />
12                 <category android:name="android.intent.category.LAUNCHER" />
13             </intent-filter>
14         </activity>
15     </application>
16     <uses-sdk android:minSdkVersion="7" />
17 </manifest> 

在这里我还想说明一下,用前者在我们应用运行后,会看到短暂的状态栏,然后才全屏,而第二种方法是不会有这种情况的,所以我建议使用后者!

posted on 2017-10-23 14:18  无网不进  阅读(733)  评论(0)    收藏  举报