Android set Full-screen and Cancel Full-screen method

Source: Internet
Author: User
Tags commit

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 ();
•}
•}
Related Article

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.