Josh Laird Josh Laird - 3 months ago 15
Android Question

Prevent StatusBar from showing when using AlertDialog.Builder

In the

XML
of my
MainActivity
, I have programmed it so that it uses a theme with
NoActionBar
and therefore there is no action bar displayed. However, whenever I want to display a dialog, I call one of my
DialogFragments
that uses an
AlertDialog.Builder
to create the dialog. When I show the dialog from within the main activity, it shows the dialog with the
ActionBar
. When I then close the dialog box, the action bar remains.

QUESTION: How do I have consistency and hide the action bar when the fragment disappears, or have it not display in the first place?

I have tried creating a custom style and then wrapping that in a
ContextThemeWrapper
to no avail.

getActionBar().hide()
and
getSupportActionBar().hide()
returns null both on the main activity and the fragment.

myDialog.getDialog()
in the MainActivity (before
.show()
is called) returns
null
.

The code I have used to create the
AlertDialog.Builder
is within
DialogFragment
's
onCreateDialog
:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.delete_confirmation)
.setItems(fileSequence, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
File loadedFile = fileFullArray.get(which);

boolean deleted = loadedFile.delete();

if (deleted)
Toast.makeText(getActivity().getApplicationContext(), "File deleted!", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
// User cancelled the dialog
}
}
);
// Create the AlertDialog object and return it
return builder.create();


EDIT:

Came back to this 4 months later and the fix was adding the following line in the Dialog's
onCreate()
:

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


The Fragment's
onCreate()
was overwriting was written in the
MainActivity
. Cheers.

Answer

The following line needed to be added to my Dialog's onCreate()

this.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Comments