1

I'm following the technique outlined here in order to have my Dialog float to the bottom of the screen and take up the full width, similar to a drawer. This works on every version of Android that I'm targeting (16+) except for Lollipop. The Dialog will float behind the software navigation buttons (back, home and stack), making it impossible to press the negative or positive buttons on my dialogs.

I've tried the method outlined here but was unsuccessful. I've considered adding a bottom padding to all of my dialogs - but this means I'll have to set custom views instead of using the alertdialog builders other methods. I think there may be a way to avoid this that I am not finding.

EDIT 1:

I've tried the setSystemUiVisibility method now, by disabling the flags for fullscreen, immersive and hide navigation. However the dialog, when created, still sits behind the navigation buttons on the screen (tested in API 22). I've also tried

decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

Here is my current code:

@Override
public void onStart()
{
    super.onStart();

    AlertDialog dlg = (AlertDialog) getDialog();

    Window window = dlg.getWindow();
    WindowManager.LayoutParams params = window.getAttributes();
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    params.gravity = Gravity.BOTTOM;

    window.setAttributes(params);
    View decor = window.getDecorView();
    int flagset = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
    decor.setSystemUiVisibility(decor.getSystemUiVisibility() & ~flagset);

}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Theme_DialogTheme);
    //various methods adding elements to dialog

    Dialog dlg = builder.create();

    return dlg;

}

and my styles:

<style name="Theme.SnapTrash" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:statusBarColor">@android:color/black</item>
    <item name="colorPrimary">@color/colorSnapTrashPrimary</item>
    <item name="android:colorBackground">@color/colorSnapTrashPrimary</item>
    <item name="android:textColorPrimary">@color/colorSnapTrashTextPrimary</item>
    <item name="android:windowBackground">?android:attr/colorBackground</item>
    <item name="colorAccent">@color/colorSnapTrashAccent</item>
    <item name="colorPrimaryDark">@color/colorSnapTrashPrimaryDark</item>
    <item name="android:colorForeground">@android:color/black</item>
    <item name="android:textColorPrimaryInverse">@color/colorSnapTrashTextPrimaryInverse</item>
    <item name="android:navigationBarColor">@android:color/black</item>
    <item name="android:textColorSecondaryInverse">@color/secondary_text_material_dark</item>
    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
    <item name="android:windowTranslucentNavigation">false</item>

</style>

<style name="Theme.DialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:windowBackground">@android:color/white</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:textColor">#FFEF5350</item>
    <item name="android:textColorPrimary">#FFEF5350</item>
    <item name="android:colorAccent">#999</item>
</style>
Kyle R
  • 99
  • 2
  • 12

1 Answers1

2

Is your navicationbar translucent? Is your dialog behind the navicationbar? If this,you can set the dialog's theme.For example,you can set the dialog's window flag not full screen,not translucent.If it doesn't work,you set the UI flag like this method:setSystemUiVisibility(int arg)

  • How can I set the inverse flags. When looking at that function I see the flags for setting it to fulscreen and translucent, however I can't figure out how to get it to do the opposite. – Kyle R Feb 28 '18 at 15:34
  • Info on toggling flags here https://stackoverflow.com/questions/47334381/what-are-these-pipe-characters/47335247#47335247 – Kyle R Feb 28 '18 at 23:55
  • I edited my code to implement the setSystemUiVisibility method and updated the op. However, this hasn't corrected the issue with the Dialog sitting behind the software navigation buttons. – Kyle R Mar 02 '18 at 19:58
  • 1
    in your onStart() code add:`getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().getDecorView().setSystemUiVisibility(0);` or ` getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().getDecorView().setSystemUiVisibility(0);` you also can set the statusbar's color,and set the navigationbar not translucent – TangXianQiang Mar 03 '18 at 02:18
  • 1
    Thank you! Like you said I needed to set false false (both need to be used) on the Theme for my Dialog not just the base Activity. This seems to work regardless of any changes I make to setSystemUiVisibility – Kyle R Mar 03 '18 at 16:23