Android中两种设置全屏的方法!!!
来源:互联网 发布:淘宝发布宝贝类别 编辑:程序博客网 时间:2024/06/07 13:12
在开发中我们经常需要把我们的应用设置为全屏,这里我所知道的有俩中方法,一中是在代码中设置,另一种方法是在配置文件里改!
一、在代码中设置:
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>
在这里我还想说明一下,用前者在我们应用运行后,会看到短暂的状态栏,然后才全屏,而第二种方法是不会有这种情况的,所以我建议
大家使用后者! 谢谢~
让程序全屏的方法,大家都知道,那是静态的,程序运行之初就申明了。但是如果有这样的需求:要在程序运行的过程中,执行了某个操作而使之全屏,然后还需要退出全屏,怎么做?
如下:Java代码
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
修改window的LayoutParams参数,然后加上FLAG_LAYOUT_NO_LIMITS标志,就OK了。window会自动重新布局,呈现全屏的状态。
要退出全屏,只需要清除刚才加上的FLAG_FULLSCREEN参数,然后去掉FLAG_LAYOUT_NO_LIMITS标志。
如下:Java代码
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(attrs);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- Android中两种设置全屏的方法!!!
- Android中两种设置全屏的方法
- Android中两种设置全屏的方法!!!
- Android中两种设置全屏的方法!!!
- Android中两种设置全屏的方法
- Android中两种设置全屏的方法
- Android中两种设置全屏的方法!!!
- Android中两种设置全屏的方法!!!
- Android设置全屏的方法
- Android设置全屏的方法
- Android设置全屏的方法
- Android设置全屏的方法
- Android设置全屏的方法
- Android设置全屏的方法
- Android设置全屏的方法
- android设置全屏以及解决设置全屏无效的方法
- Android基础教程之-------Android中两种设置全屏的方法!!!
- Android中两种设置全屏的方法 && Android横竖屏切换
- 前端 json字符串转换成json对象
- 资源国际化
- JS事件监听器
- checkbox android:button="@null" 默认checkbox icon仍占位问题
- SSH:Struts1框架(MVC讲解)
- Android中两种设置全屏的方法!!!
- Linux下使用scp&sftp传输文件
- 关于Random.Range 范围的学习
- visual studio 2010编译器设置备注
- 怎么在程序内部确定程序自己的绝对路径(windows,linux)
- Unity3D之Animation中AnimationEvent的BUG?爬坑向
- WLAN控制器 - CAPWAP协议简介
- mybatis中的#和$的区别
- LightOJ 1340 Story of Tomisu Ghost