Android隐藏状态栏和标题栏,相当于全屏效果

来源:互联网 发布:sql2005数据库补丁 编辑:程序博客网 时间:2024/04/29 07:14

这里还有一篇:

http://blog.csdn.net/androidzhaoxiaogang/article/details/6825163




隐藏标题栏需要使用预定义样式:android:theme=”@android:style/Theme.NoTitleBar”.
隐藏状态栏:android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”.

[XML]代码

01<?xmlversion="1.0"encoding="utf-8"?>
02<manifestxmlns:android="http://schemas.android.com/apk/res/android"
03package="de.vogella.android.temperature"
04android:versionCode="1"
05android:versionName="1.0">
06<applicationandroid:icon="@drawable/icon"android:label="@string/app_name">
07<activityandroid:name=".Convert"
08android:label="@string/app_name"
09android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
10<intent-filter>
11<actionandroid:name="android.intent.action.MAIN"/>
12<categoryandroid:name="android.intent.category.LAUNCHER"/>
13</intent-filter>
14</activity>
15 
16</application>
17<uses-sdkandroid:minSdkVersion="9"/>
18 
19</manifest>

[代码] [Java]代码

01@Override
02publicvoidonCreate(Bundle savedInstanceState) {
03super.onCreate(savedInstanceState);
04// hide titlebar of application
05// must be before setting the layout
06requestWindowFeature(Window.FEATURE_NO_TITLE);
07// hide statusbar of Android
08// could also be done later
09getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
10WindowManager.LayoutParams.FLAG_FULLSCREEN);
11setContentView(R.layout.main);
12text = (EditText) findViewById(R.id.EditText01);
13 
14}

Android中两种设置全屏的方法
2011-09-01 9:41

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

一、在代码中设置:

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);
}
}

在这里要强调一点,设置全屏的俩段代码必须在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>


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