Home » Android » Android make Dialog fullscreen with status bar showing

Android make Dialog fullscreen with status bar showing

Posted by: admin June 15, 2020 Leave a comment

Questions:

I want to make a dialog box with full screen but not hiding the status bar.

If use style Theme_Light_NoTitleBar_Fullscreen, the dialog box occupies the whole screen.

If use style Theme_Material_Light_NoActionBar_TranslucentDecor, it seems working but the top of the dialog box actually is becoming transparent. I can make it better by enquiring the status bar height and add top padding to my dialog layout. This solution seems works fine, except it does not work if I attached an animation to it.

I am very confused why Google make the dialog box so complicated to use, and if I am doing correctly to make a full screen dialog box here?

How to&Answers:

Just use THEME_BLACK_NoTitleBar
Worked For me!!!

Answer:

It maybe too late but for the sake of others who have the same problem :

    dialog = new dialog(context,android.R.style.Theme_Translucent_NoTitleBar);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                                 WindowManager.LayoutParams.MATCH_PARENT);

Answer:

I have found a snipplet from a blog, after a few tries i found that i have to use Theme_Black_NoTitleBar_Fullscreen in constructor, together with the snipplet during onCreate. now my dialog is fullscreen and shows status bar.

public YourCustomDiag(Activity act){
    //step 1, required. to stretch the dialog to full screen
    super(act, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.custom_dialog_layout);
    KeepStatusBar();
}

//step 2, required
private void KeepStatusBar(){    
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    getWindow().setAttributes(attrs);
}

this is the source where i found the snipplet

Answer:

Use android.R.style.Theme_Black_NoTitleBar

AlertDialog.Builder builder = new AlertDialog.Builder(context,
                   android.R.style.Theme_Black_NoTitleBar);

Example screen