How can I show SnackBar under FragmentDialog?

I have activity with a FragmentDialog . In the onResume this dialog box, I set its height and weight 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 great, the background has a shadow, the foreground FragmentDialog has the correct dimensions. Question: how can I show a SnackBar at the bottom of the screen that is not affected by the FragmentDialog (shadow, activity type) without shadow? Is there a way to turn off the shadow for a specific view in action that is in the background of a FragmentDialog ?

+6
source share
1 answer

The material design documentation states: “ Captures are displayed above most of the elements on the screen, and they are equal in height for a button with a floating action. However, they are lower in height than dialogs, bottom sheets and navigation boxes .” From there, I think you should consider displaying the Snackbar inside DialogFragment or just display a small dialog on top of it.

If you want to display the Snackbar inside the dialog box, you can 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 whole dialog box. You can improve it by creating the root view of a fragment of a CoordinatorLayout and showing the Snackbar in this view.
+1
source

All Articles