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>   

 

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值