Dialog full screen the way to remove the status bar

  • 2021-11-29 08:30:01
  • OfStack

Even if dialog is set to full screen, there is still a status bar occupying height.

Just put the following line of code into your dialog


 @Override
 protected void onStart() {
  super.onStart();
  int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_IMMERSIVE
    | View.SYSTEM_UI_FLAG_FULLSCREEN;
  this.getWindow().getDecorView().setSystemUiVisibility(uiOptions);
 }

By the way, customize dialog width and height:


WindowManager.LayoutParams attributes = getWindow().getAttributes();
  attributes.width = width;
  attributes.height = height;
  getWindow().setAttributes(attributes);

Add two basic style


 <!-- Ordinary dialog Style -->
 <style name="customerDialog" parent="@android:style/Theme.Dialog">
  <item name="android:windowFrame">@null</item>
  <item name="android:windowIsFloating">true</item>
  <item name="android:windowIsTranslucent">true</item>
  <item name="android:windowNoTitle">true</item>
  <item name="android:background">@android:color/transparent</item>
  <!-- <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> -->
  <item name="android:windowBackground">@android:color/transparent</item>
  <item name="android:windowSoftInputMode">stateHidden|adjustPan</item>
 </style>


 <!-- Transparent background dialog Style -->
 <style name="TransparentDialogStyle" parent="@android:style/Theme.Dialog">
  <item name="android:windowBackground">@android:color/transparent</item>
  <item name="android:windowNoTitle">true</item>
  <item name="android:backgroundDimEnabled">false</item>
 </style>

Supplementary knowledge: Android summary of full screen setting and hidden status bar and immersive status bar

1. Full Screen and Roll Out Full Screen

Achieve full screen

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

There is a method of View. setLayoutparams. Note that this LayoutParams is not followed by its own LayoutParams but by the parent container's layoutParams

Exit full screen


final WindowManager.LayoutParams attrs = getWindow().getAttributes();
   attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
   getWindow().setAttributes(attrs);
   getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

2. Hide the status bar

getWindow().getDecorView().setSystemUiVisibility(View.INVISIBLE);

Parameters:

View. SYSTEM_UI_FLAG_VISIBLE: Displays status bar, Activity is not displayed in full screen (reverts to normal status).

View. INVISIBLE: Hides the status bar while Activity stretches full screen.

View. SYSTEM_UI_FLAG_FULLSCREEN: Activity is displayed in full screen and the status bar is hidden and overwritten.

View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN: Activity is displayed in full screen, but the status bar will not be hidden and overwritten, the status bar will still be visible, and the top layout part of Activity will be obscured by the status.

View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION: Same effect as View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

View.SYSTEM_UI_LAYOUT_FLAGS: Same effect as View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

View. SYSTEM_UI_FLAG_HIDE_NAVIGATION: Hides virtual keys (navigation bar). Some phones use virtual buttons instead of physical buttons.

View.SYSTEM_UI_FLAG_LOW_PROFILE: The status bar display is in the low-energy display state (low profile mode), and one icon display on the status bar will be hidden.

3. Immersive status bar (android4.4 began to be introduced)

(1). Through SystemBarTintManager


 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  setTranslucentStatus(true);
  SystemBarTintManager tintManager = new SystemBarTintManager(this);
  tintManager.setStatusBarTintEnabled(true);
  tintManager.setStatusBarTintResource(R.color.color_top_bg);//  Required color for notification bar 
  }

    @TargetApi(19)
 private void setTranslucentStatus(boolean on) {
 Window win = getWindow();
 WindowManager.LayoutParams winParams = win.getAttributes();
 final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
 // WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
 if (on) {
  winParams.flags |= bits;
 } else {
  winParams.flags &= ~bits;
 }
 win.setAttributes(winParams);
 }

(2). Add view with the same color as ActionBar at the top (if tittlebar appears after setting, configure style of activity to NoTittlebar in the manifest file)


 Window window = getWindow(); 
 window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
 ViewGroup decorView = (ViewGroup) window.getDecorView();
 view = new View(this);
 view.setLayoutParams(new ViewGroup.LayoutParams(
  ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(this)));
 view.setBackgroundColor(getResources().getColor(R.color.color_top_bg));
 decorView.addView(view);

Related articles: