简体   繁体   English

浮动动作按钮在第二个Snackbar下消失

[英]Floating Action Button diasappears under SECOND Snackbar

I'm using a CoordinatorLayout to keep my Floating Action Button above the Snackbar, which works great. 我正在使用CoordinatorLayout将浮动操作按钮保持在Snackbar上方,效果很好。 ...But only for the first Snackbar. ...但仅限于第一个Snackbar。 When a second one is created, while the first one is still there, the FAB slides under it. 创建第二个时,第一个仍在其中,而FAB则在其下方滑动。

I'm using this in a RecyclerView in which I can remove items. 我在RecyclerView中使用它,可以在其中删除项目。 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) 因此,当您一个接一个地删除某些项目时,可见的Snackbar被一个新的替换(这会导致FAB行为)

Do you know a solution to keep the FAB above new Snackbars? 您是否知道将FAB保持在新的小吃店之上的解决方案?

<?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 这是我删除项目后的样子

在此处输入图片说明

...and then after I delete another item ...然后删除其他项目

在此处输入图片说明

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 这将始终发生,因为快餐栏是视图上方的一层。在这种情况下,不应使用堆叠的快餐栏。请参见google gidelines。https ://www.google.co.in/design/spec/components/snackbars- toasts.html#小吃店,敬酒使用率

On the contrary, you implementation should be something like https://github.com/jenzz/Android-UndoBar 相反,您的实现应类似于https://github.com/jenzz/Android-UndoBar

Apologies for changing ur design 更改设计的歉意

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM