Android offers two ways to achieve no title bar and Full-screen effects, either declaratively through an XML file or dynamically controlled in a program.
Android Set Full-screen method
First, through the program settings:
The code is as follows |
Copy Code |
package com.hhh.changeimage; import android.app.Activity; Import Android.os.Bundle; import Android.view.Window; import Android.view.WindowManager; public class Changeimage extends activity { public void OnCreate (Bundle savedinstancestate) { super.oncreate ( Savedinstancestate); //No TITLE requestwindowfeature (window.feature_no_title); GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, Windowmanager.layoutparams. Flag_fullscreen); Setcontentview (R.layout.main); } } |
Note: No title and full screen segment code must be before Setcontentview (R.layout.main), or it will be an error.
Second, in the configuration file modification (androidmanifest.xml)
The code is as follows |
Copy Code |
<activity android:name= ". Changeimage " 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> |
Below we combine the above example to make an Android Full-screen setting and cancel the full screen setting
• 1.//Insert before Setcontentview () in Oncreat method
The code is as follows |
Copy Code |
requestwindowfeature (window.feature_no_title)//Cancel title bar GetWindow (). SetFlags (Windowmanager.layoutparams. Flag_fullscreen, Windowmanager.layoutparams. Flag_fullscreen);/Full Screen
|
Note: This method flashes the status bar after the activity is started and then full screen
• 2, inside the manifest configuration: <activity android:theme= "@android: Style/theme.notitlebar.fullscreen"/> Only in the current Activity display full screen
<application android:theme= "@android: Style/theme.notitlebar.fullscreen"/> Full screen display for the entire application
• 3,/**
* Full Screen switching
• */
The code is as follows |
Copy Code |
public void Fullscreenchange () { sharedpreferences mpreferences = preferencemanager.getdefaultsharedpreferences (this); Boolean fullscreen = Mpreferences.getboolean ("fullscreen", false); Windowmanager.layoutparams attrs = GetWindow (). GetAttributes (); System.out.println ("fullscreen value:" + fullscreen); if (fullscreen) { attrs.flags &= (~windowmanager.layoutparams.flag_fullscreen); GetWindow (). SetAttributes (Attrs); //Cancel full screen settings GetWindow (). Clearflags (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); · Mpreferences.edit (). Putboolean ("fullscreen", false). commit (); •} else { attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; GetWindow (). SetAttributes (Attrs); GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); Mpreferences.edit (). Putboolean ("fullscreen", true). commit (); •} •} |