I have an activity with a coordinator layout. Inside the coordinator layout is a view which inherits the default bottom sheet layout behavior for the Google Support Library Bottom Sheet. The issue is that when I call Snackbar.show() with the coordinator layout as the view, the bottomsheet pops up as well.
Here is the call to show snackbar:
Snackbar.make(coordinatorLayout, R.string.status_image_saved,
Snackbar.LENGTH_SHORT).show();
Here is the layout:
<android.support.design.widget.CoordinatorLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView />
</android.support.constraint.ConstraintLayout>
<LinearLayout
android:id="@+id/attachment_selector"
android:layout_width="match_parent"
android:layout_height="480dp"
android:background="@color/colorBack"
android:elevation="10dp"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="@dimen/bottom_sheet_start"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<android.support.design.widget.TabLayout
android:id="@+id/attachment_selector_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="@+id/attachment_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
It's a late answer but might be helpful for others.
If you are using a Dialog
or BottomSheetDialog
you can show a Snackbar
providing the top-level window decor view.
Here's my solution in Kotlin:
Snackbar.make(
dialog.window.decorView, // important part
"your-string",
Snackbar.LENGTH_SHORT
).show()
The solution using dialog.window.decorView
appeared over Android's soft navigation keys for me. Instead I shifted the Snackbar's elevation to be greater than the BottomSheetDialog
's elevation.
This keeps the Snackbar at the correct position in the y-axis and the new elevation brings it above the bottom sheet:
Snackbar.make(binding.root, "Example", Snackbar.LENGTH_LONG)
.apply {
view.elevation = 1000F
}.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With