Get the App
SLTechnology News&Howtos  ›  Development  › 

How to switch between full screen and non-full screen in Android

Shulou Source: shulou.com Published: 2022-06-01 00:17:16 10月05日 Update

This article introduces the knowledge of "how to switch between full-screen and non-full-screen in Android". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Static method

1. Code mode

Set it in the OnCreate method of the Activity class, as follows

@ Overrideprotected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); requestWindowFeature (Window.FEATURE_NO_TITLE); getWindow () .setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView (R.layout.activity_main);}

RequestWindowFeature and getWindow (). SetFlags must be placed before the setContentView method

two。 File configuration mode

In the AndroidManifest.xml file, locate the properties and set them as follows:

Android:theme= "@ android:style/Theme.NoTitleBar.Fullscreen"

Dynamic method

1. Window mode

If (mIsFullScreen) {/ / set to non-full screen WindowManager.LayoutParams lp = getWindow () .getAttributes (); lp.flags & = (~ WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow () .setAttributes (lp); getWindow () .clearFlags (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);} else {/ / set to full screen WindowManager.LayoutParams lp = getWindow () .getAttributes (); lp.flags | = WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow () .setAttributes (lp) GetWindow () .addFlags (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);}

2. View mode

If (mIsFullScreen) {/ / is set to non-full-screen getWindow () .getDecorView (). SetSystemUiVisibility (View.SYSTEM_UI_FLAG_VISIBLE);} else {/ / is set to full-screen getWindow (). GetDecorView (). SetSystemUiVisibility (View.SYSTEM_UI_FLAG_FULLSCREEN);} "how to switch between full-screen and non-full-screen in Android" ends here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Ways methods switching code content files more knowledge practicality learning and then dynamic dilemma reality attributes situations articles cases editing websites Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Xiaomi Microsoft Redmi Linux