Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I show SnackBar under FragmentDialog?

I have an activity with FragmentDialog. In onResume of this dialog I set height and weight of it to 80% and 90% by code:

WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.copyFrom(getDialog().getWindow().getAttributes());
layoutParams.width = (int)(screenWidth * 0.9);
layoutParams.height = (int)(screenHeight * 0.8);

getDialog().getWindow().setAttributes(layoutParams);

It works perfectly, background has shadow, foreground FragmentDialog has proper dimensions. Question is - how can I show SnackBar at the bottom of the screen not affected by FragmentDialog (one that has shadow, Activity view) without shadow? Is there any way to disable shadow for specific view at activity that is in background of FragmentDialog?

like image 614
KWA Avatar asked Dec 11 '15 07:12

KWA


Video Answer


1 Answers

Material design documentation says "Snackbars appear above most elements on screen, and they are equal in elevation to the floating action button. However, they are lower in elevation than dialogs, bottom sheets, and navigation drawers". From there, I think you should consider displaying the Snackbar inside the DialogFragment or just display a small dialog on top of it.

If you want to display Snackbar inside dialog fragment, you could do something like this:

public void showSnackBar(final View parent, final String text) {
    Snackbar sb = Snackbar.make(parent, text, Snackbar.LENGTH_LONG);
    sb.show();
}
  • NOTE: parent is the entire dialog's view. You could improve it by making the root view of the fragment a CoordinatorLayout and showing the Snackbar on that view.
like image 172
Pablo S. Campos Avatar answered Oct 20 '22 05:10

Pablo S. Campos