1

I'm using a CoordinatorLayout to keep my Floating Action Button above the Snackbar, which works great. ...But only for the first Snackbar. When a second one is created, while the first one is still there, the FAB slides under it.

I'm using this in a RecyclerView in which I can remove items. When an item is removed, a "Undo" Snackbar appears. So when you delete some items one after another, the visible Snackbar is replaced by a new one (which causes the FAB behaviour)

Do you know a solution to keep the FAB above new Snackbars?

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fab="http://schemas.android.com/tools"
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:backgroundTint="@color/background_grey"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical" />

    </LinearLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_marginBottom="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:elevation="6dp"
            android:src="@drawable/ic_add_white_36dp"
            app:borderWidth="0dp"
            app:fabSize="normal"
            app:pressedTranslationZ="10dp"
            app:rippleColor="@color/abc_primary_text_material_dark" />

</android.support.design.widget.CoordinatorLayout>

This is how it looks after I delete on item

enter image description here

...and then after I delete another item

enter image description here

Nglhrdtptrck
  • 175
  • 7
  • You'll want to add the Snackbar to the CoordinatorLayout. http://stackoverflow.com/a/32777587/2444099 – Eugen Pechanec Oct 12 '15 at 10:09
  • Possible duplicate of [Moving Floating Action Button up and down to avoid getting blocked by a snackbar](http://stackoverflow.com/questions/27912656/moving-floating-action-button-up-and-down-to-avoid-getting-blocked-by-a-snackbar) – Eugen Pechanec Oct 12 '15 at 10:09
  • Sorry, but it didn't work. Same issue – Nglhrdtptrck Oct 14 '15 at 08:20

1 Answers1

0

This will always happen, as snackbar is a layer above the view ..Stacked snackbar shouldn't be used in this scenario See google gidelines.. https://www.google.co.in/design/spec/components/snackbars-toasts.html#snackbars-toasts-usage

On the contrary, you implementation should be something like https://github.com/jenzz/Android-UndoBar

Apologies for changing ur design

Ashish Rawat
  • 5,541
  • 1
  • 20
  • 17
  • Thanks. My Snackbars aren't stacked. When one is displayed and I remove another item from the RecyclerView the new Snackbar replaces the old. It does NOT look like Screenshot 4 of the Google Design Guidelines. But isn't the Snackbar (with an action) exactly what is necessary in this scenario? Just like swiping away Google Now Cards – Nglhrdtptrck Oct 12 '15 at 13:21
  • I attached some screenshots to the opening post – Nglhrdtptrck Oct 12 '15 at 13:29
  • 1
    Its actually responsibility of co-ordinate layout to handle this,every time snackbar appear, however in this case there is some bug.. One thing that is important to note is that CoordinatorLayout doesn’t have any innate understanding of a FloatingActionButton or AppBarLayout work - it just provides an additional API in the form of a Coordinator.Behavior, which allows child views to better control touch events and gestures as well as declare dependencies between each other and receive callbacks via onDependentViewChanged(). U need to play around with these 2 methods.. – Ashish Rawat Oct 12 '15 at 17:44
  • Check this out, can be helpful...though urs is native, neverthless overriding that event , will give some insight https://lab.getbase.com/introduction-to-coordinator-layout-on-android/ – Ashish Rawat Oct 16 '15 at 16:23