Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6535825
  • 博文数量: 915
  • 博客积分: 17977
  • 博客等级: 上将
  • 技术积分: 8846
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-26 09:59
个人简介

一个好老好老的老程序员了。

文章分类

全部博文(915)

文章存档

2022年(9)

2021年(13)

2020年(10)

2019年(40)

2018年(88)

2017年(130)

2015年(5)

2014年(12)

2013年(41)

2012年(36)

2011年(272)

2010年(1)

2009年(53)

2008年(65)

2007年(47)

2006年(81)

2005年(12)

分类: Java

2011-05-24 12:53:17

在开发中我们经常需要把我们的应用设置为全屏,这里我所知道的有俩中方法,一中是在代码中设置,另一种方法是在配置文件里改!
一、在代码中设置:
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?
"1.0" encoding="utf-8"?>        
"http://schemas.android.com/apk/res/android"    
            package="com.android.tutor"    
            android:versionCode="1"    
            android:versionName="1.0">        
        "@drawable/icon" android:label="@string/app_name">        
                ".OpenGl_Lesson1"    
                                    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"    
                                    android:label="@string/app_name">        
                                
                                "android.intent.action.MAIN" />        
                                "android.intent.category.LAUNCHER" />        
                        
        
                
        
        
        
        "7" />        
        
"1.0" encoding="utf-8"?>
"http://schemas.android.com/apk/res/android"
            package="com.android.tutor"
            android:versionCode="1"
            android:versionName="1.0">
        "@drawable/icon" android:label="@string/app_name">
                ".OpenGl_Lesson1"
                        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                                    android:label="@string/app_name">
                        
                                "android.intent.action.MAIN" />
                                "android.intent.category.LAUNCHER" />
                        

                

        

        "7" />
    

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

本文出自 “Android_Tutor” 博客,请务必保留此出处http://weizhulin.blog.51cto.com/1556324/311464

阅读(2334) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~