本文实例讲述了Android编程设置全屏的方法。分享给大家供大家参考,具体如下:
在实际的应用程序开发中,我们有时需要把 Activity 设置成全屏显示,一般情况下,可以通过两种方式来设置全屏显示效果。其一,通过在代码中可以设置,其二,通过manifest配置文件来设置全屏。
其一:在代码中设置(如下)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package xiaohang.zhimeng;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class Activity01 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
//设置为无标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置为全屏模式
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//设置为横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.main);
}
}
|
但要注意的是:在代码中设置的话,设置无标题和设置全屏的两段代码要放置在 setContentView(R.layout.main); 这段代码的前面。要不然会报错。
其二:在manifest配置文件中设置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<? xml version = "1.0" encoding = "utf-8" ?>
< manifest xmlns:android = "http://schemas.android.com/apk/res/android"
package = "com.ladygaga.playboy"
android:versionCode = "1"
android:versionName = "1.0" >
< uses-sdk android:minSdkVersion = "8" />
< application android:icon = "@drawable/icon" android:label = "@string/app_name" >
< activity android:name = "com.ladygaga.test.ImageSwitcherTest"
android:screenOrientation = "sensor"
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 >
</ manifest >
|
或:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<? xml version = "1.0" encoding = "utf-8" ?>
< manifest xmlns:android = "http://schemas.android.com/apk/res/android"
package = "com.ladygaga.playboy"
android:versionCode = "1"
android:versionName = "1.0" >
< uses-sdk android:minSdkVersion = "8" />
< application android:icon = "@drawable/icon"
android:theme = "@android:style/Theme.NoTitleBar.Fullscreen"
android:label = "@string/app_name" >
< activity android:name = "com.ladygaga.test.ImageSwitcherTest"
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 >
</ manifest >
|
在相应的Activity中节点中添加属性:
复制代码 代码如下:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
即可以设置某个Activity全屏显示。若设置成 android:theme="@android:style/Theme.NoTitleBar" 即是只是设置成无标题状态。
希望本文所述对大家Android程序设计有所帮助。