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" >
<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" >
<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