In Android, you can set full screen !!!

Source: Internet
Author: User

Http://hi.baidu.com/sunyaming/blog/item/fec4450e6b0191c77acbe182.html

During development, we often need to set our applications to full screen. Here I know two methods. One is to set them in code, another way is to change it in the configuration file!

1. Set in the Code:

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 );
// No title
Requestwindowfeature (window. feature_no_title );
// Full screen
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 );
// No title
Requestwindowfeature (window. feature_no_title );
// Full screen
Getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen,
Windowmanager. layoutparams. flag_fullscreen );

Setcontentview (R. layout. Main );
}
}

It should be emphasized that the full screen code must be before setcontentview (R. layout. Main), or an error will be reported.

2. modify it in the configuration file (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" type = "codeph" text = "/codeph">
<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" type = "codeph" text = "/codeph">
<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>

Here I would like to explain that the former will see a short status bar after we run the application, and then the full screen will be displayed. This is not the case in the second method, so I suggest

Use the latter! Thank you ~

 

The full screen method of the program is known to all. It is static and stated at the beginning of the program running. However, if you want to execute an operation while running the program to make it full screen, you still need to exit full screen. How can this problem be solved?

The Java code is as follows:

Windowmanager. layoutparams attrs = getwindow (). getattributes ();
Attrs. Flags | = windowmanager. layoutparams. flag_fullscreen;
Getwindow (). setattributes (attrs );
Getwindow (). addflags (windowmanager. layoutparams. flag_layout_no_limits );

Modify the layoutparams parameter of the window and add the flag_layout_no_limits flag to it. Window is automatically displayed in full screen mode.

To exit full screen, you only need to clear the flag_fullscreen parameter that you just added, and then remove the flag_layout_no_limits flag.

The Java code is as follows:

Windowmanager. layoutparams attrs = getwindow (). getattributes ();
Attrs. Flags & = (~ Windowmanager. layoutparams. flag_fullscreen );
Getwindow (). setattributes (attrs );
Getwindow (). clearflags (windowmanager. layoutparams. flag_layout_no_limits );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.