question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BottomSheetDialogFragment] Snackbar invisible when showing from BottomSheetDialogFragment

See original GitHub issue

Description: Full description of issue here

SnackBar invisible when showing from BottomSheetDialogFragment

Expected behavior: Screenshots and/or description of expected behavior

SnackBar visible when showing from BottomSheetDialogFragment

Source code: The code snippet which is causing this issue. Please consider attaching a minimal sample app that reproduces the issue.

class MyBottomSheetDialogFragment : BottomSheetDialogFragment() {

  override fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
  ): View? = createMyView()

  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    Snackbar.make(view, "Test", Snackbar.LENGTH_INDEFINITE).show()
  }
}

Android API version: Android API version here

29

Material Library version: Material Android Library version you are using here (e.g., 1.1.0-alpha07)

1.2.1

Device: Device on which the bug was encountered here

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

BottomSheet has a default elevation 16dp while Snackbar has a default elevation 6dp. Maybe BotomSheetTheme should override the default Snackbar style to have a larger elevation.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
michaldrabikcommented, Dec 25, 2021

it’s either the first CoordinatorLayout in the parent chain,

With this in mind what I’m doing as a “hack” is to add an empty CoordinatorLayout into my BottomSheet layout and using it as a snackbar host.

Snackbars are then displayed properly.

<androidx.constraintlayout.widget.ConstraintLayout >

  // All the content views here ...

  <androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/contextMenuItemSnackbarHost"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    />

</androidx.constraintlayout.widget.ConstraintLayout>

1reaction
drchencommented, Feb 1, 2022

Hi folks, after several rounds of brainstorming and discussion with the team, we don’t really feel there’s a perfect solution for this.

Under the current implementation we have to find a suitable parent of the provided reference view to add snackbar to - and this parent has to be a frame/relative layout-like view group. (We use the first CoordinatorLayout we find or the root.) Due to the restriction of this, we cannot avoid that the reference view (or any other views under the same parent) has a higher elevation than the snackbar; and what makes things worse is that there’s no simple way to check if two views’ visible areas are overlapped.

The best solution we can think of is making Snackbars dialogs, but this may break the existing behavior, especially we need to support all existing extensions of BaseTransientBottomBar.

We will need to spend more time on investigating the dialog solution, so let me close this issue as WAI/infeasible for now.

The solution mentioned by @michaldrabik is a good workaround, if you don’t need to set Snackbar’s anchor view. (I didn’t try it, but it may work with it as well actually.)

Another possible workaround is customizing ?attr/snackbarStyle (by default Widget.Material3.Snackbar in M3) and setting a higher elevation to it, depending on your use case.

Hope this helps!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to show SnackBar in BottomSheetDialogFragment?
Solution is fairly simple. You need to: Wrap your dialog layout with CoordinatorLayout (and if you want to show snackbar just next to...
Read more >
BottomSheetDialogFragment - Android Developers
This is a version of DialogFragment that shows a bottom sheet using BottomSheetDialog instead of a floating dialog. Summary. Inherited constants.
Read more >
Sheets: bottom - Material Design
STATE_COLLAPSED: The bottom sheet is visible but only showing its peek height. ... BottomSheetDialogFragment is a thin layer on top of the regular...
Read more >
How To Show Snackbar Under Fragmentdialog? - ADocLib
When a Snackbar is rendered it normally appears at the bottom of the visible Show 1 more comment Add this line in bottom...
Read more >
Make Android apps more accessible to all - ProAndroidDev
Once a task is archived, a snackbar appears on the bottom of the screen that ... to determine how long the snackbar should...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found