Android Full Screen control: dynamically toggle fullscreen and non-fullscreen

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/michaelpp/article/details/7302308

Dynamically toggle fullscreen and non-fullscreen:

Package com.screen;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.WindowManager;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;

public class Mainactivity extends Activity {

Private Boolean isfulllscreen = false;
Private button button;

@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Button = (button) Findviewbyid (R.id.button);
Button.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
Isfulllscreen =!isfulllscreen;
if (Isfulllscreen) {
Button.settext (Getresources (). GetText (R.string.exit_full_screen));
Windowmanager.layoutparams params = GetWindow (). GetAttributes ();
Params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
GetWindow (). SetAttributes (params);
GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
} else {
Button.settext (Getresources (). GetText (R.string.full_screen));
Windowmanager.layoutparams params = GetWindow (). GetAttributes ();
Params.flags &= (~windowmanager.layoutparams.flag_fullscreen);
GetWindow (). SetAttributes (params);
GetWindow (). Clearflags (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
}
});

}
}

non-dynamic full-screen settings:

In the actual application development, we sometimes need to set the Activity to display the full screen, in general, there are two ways to set the screen display effect. One is to set the full screen through the manifest configuration file by setting it in code.


One: Set in code (below)


View Plaincopy to Clipboardprint?
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);

Set Untitled
Requestwindowfeature (Window.feature_no_title);
Set Full Screen
GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

Setcontentview (R.layout.main);
}

However, it is important to note that in the code, set the untitled and set the full screen of the two-segment code to be placed in the Setcontentview (R.layout.main); In front of this piece of code. Otherwise you will get an error.


Second: Set in the manifest configuration file


View Plaincopy to Clipboardprint?
<?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Com.andyidea"
Android:versioncode= "1"
Android:versionname= "1.0" >
&LT;USES-SDK android:minsdkversion= "8"/>
<application android:icon= "@drawable/icon" android:label= "@string/app_name" >
<activity android:name= ". Login. Loginactivity "
Android:theme= "@android: style/android. 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>
</manifest>

Add a property to the node in the corresponding activity: android:theme= "@android: Style/theme.notitlebar.fullscreen" To set an activity full-screen display. If set to Android:theme= "@android: Style/theme.notitlebar" is just set to untitled state.

In the actual application development, we sometimes need to set the Activity to display the full screen, in general, there are two ways to set the screen display effect. One is to set the full screen through the manifest configuration file by setting it in code.


One: Set in code (below)


View Plaincopy to Clipboardprint?
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);

Set Untitled
Requestwindowfeature (Window.feature_no_title);
Set Full Screen
GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

Setcontentview (R.layout.main);
}

However, it is important to note that in the code, set the untitled and set the full screen of the two-segment code to be placed in the Setcontentview (R.layout.main); In front of this piece of code. Otherwise you will get an error.


Second: Set in the manifest configuration file


View Plaincopy to Clipboardprint?
<?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Com.andyidea"
Android:versioncode= "1"
Android:versionname= "1.0" >
&LT;USES-SDK android:minsdkversion= "8"/>
<application android:icon= "@drawable/icon" android:label= "@string/app_name" >
<activity android:name= ". Login. Loginactivity "
Android:theme= "@android: style/android. 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>
</manifest>

Add a property to the node in the corresponding activity: android:theme= "@android: Style/theme.notitlebar.fullscreen" To set an activity full-screen display. If set to Android:theme= "@android: Style/theme.notitlebar" is just set to untitled state.

(GO) Android full screen control: dynamically toggle fullscreen and non-fullscreen

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.