简体   繁体   English

Snackbar在按下动作按钮时隐藏了浮动动作

[英]Snackbar hides the Floating Action on pressing the action button on it

I am working on Snack bar and Floating Action button. 我正在研究Snack bar和Floating Action按钮。 I used Coordinator layout for making the Floating action button to appear/move when snackbar is displayed. 我使用协调器布局使浮动操作按钮在显示快餐栏时显示/移动。 The problem is i kept an action for snackbar . 问题是我为小吃店保留了一个动作。 When the floating button is tapped , Snackbar is popping up and Floating action button is moving up. 点击浮动按钮时,Snackbar会弹出,并且浮动操作按钮会向上移动。 And when i pressed the snackbar action item , the floating action button is getting hidden under the child snackbar. 当我按下快餐栏动作项时,浮动动作按钮隐藏在儿童零食栏下面。

And also if i press floating action button consecutively , then also floating action button is getting hidden. 而且如果我连续按下浮动动作按钮,那么浮动动作按钮也会被隐藏。

Following is my code. 以下是我的代码。

activity_main.xml activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.dev.firsttest.Screen2"
>

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/primary_color"></android.support.v7.widget.Toolbar>

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/coordinatorlayout">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/searchfab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="20dp"
        android:src="@drawable/ic_add_black_24dp"
        app:fabSize="normal">

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

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

MainActivity 主要活动

Toolbar toolbar;
FloatingActionButton searchfab;
CoordinatorLayout coordinatorLayout;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_screen2);

    toolbar = (Toolbar)findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    coordinatorLayout = (CoordinatorLayout)findViewById(R.id.coordinatorlayout);

    searchfab = (FloatingActionButton)findViewById(R.id.searchfab);
    searchfab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Snackbar.make(coordinatorLayout, "This is Snackbar Demo", Snackbar.LENGTH_LONG).setAction("Click", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Snackbar.make(coordinatorLayout, "This is Child Snackbar", Snackbar.LENGTH_LONG).show();
                }
            }).show();
        }
    });


}

Pressing Child action in Snackbar and consecutive taps on Floating action button makes the Floating action button hides back to the Snackbar 在Snackbar中按子操作并在浮动操作按钮上连续点击会使浮动操作按钮隐藏回Snackbar

Appreciate your help 感谢您的帮助

Thank you 谢谢

The answer its here: https://github.com/ggajews/coordinatorlayoutwithfabdemo . 答案在这里: https//github.com/ggajews/coordinatorlayoutwithfabdemo

It will move the FAB when the snackbar is shown. 当快餐栏显示时,它将移动FAB。

I was not able to reproduce your issue. 我无法重现您的问题。 Here is my code 这是我的代码

View.OnClickListener test1 = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(getActivity().findViewById(R.id.snackbarPosition), "test 1", Snackbar.LENGTH_LONG)
                        .setAction(R.string.snackbar_action_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                 Snackbar.make(getActivity().findViewById(R.id.snackbarPosition), "test 2", Snackbar.LENGTH_LONG)
                                        .setActionTextColor(getResources().getColor(R.color.myBlueGreen))
                                        .show();
                            }
                        })
                        .show();
            }
        };

FloatingActionButton button = (FloatingActionButton)streamView.findViewById(R.id.buttonFloat);
button.setOnClickListener(test1); 

XML XML

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textColor="@android:color/white"
    android:id="@+id/snackbarPosition">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/buttonFloat"
        android:src="@drawable/ic_content_new"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="20dp"
        app:backgroundTint="@color/myBlueGreen"

        app:elevation="6dp"
        app:pressedTranslationZ="12dp"
        />

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

Adding a second snackbar "test2" appear as a OnClickListener on the snackbar "test1", for me, replaces the snackbar "test1" by "test2" (and does not hide the Floating action button) 添加第二个快餐栏“test2”在小吃栏“test1”上显示为OnClickListener,对我来说,用“test2”替换小吃栏“test1”(并且不隐藏“浮动”按钮)

Also, clicking twice on Floating Action Button makes the snackbar "test1" blink, ie appear twice but not two snackbars one on top of each other. 此外,在“浮动操作按钮”上单击两次会使快餐栏“test1”闪烁,即两次出现两次,而不是两个小吃栏。 The floating action button does not disappear. 浮动操作按钮不会消失。

In other words I never see a "child" snackbar on top of a "parent" snackbar. 换句话说,我从来没有在“父母”小吃店顶部看到一个“儿童”小吃店。

I cannot see a difference between your code and mine. 我看不出你和我的代码之间的区别。 Maybe try copying my code and see if it solves your problem. 也许尝试复制我的代码,看看它是否解决了你的问题。

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

相关问题 浮动动作按钮+小吃栏的容器 - Container for Floating Action Button + Snackbar Snackbar顶部的浮动动作按钮。 怎么样? - Floating Action Button on top of Snackbar. How? 带有多行的浮动操作按钮 Snackbar - Floating Action Button Snackbar with multi line 浮动动作按钮在第二个Snackbar下消失 - Floating Action Button diasappears under SECOND Snackbar 如果在 CoordinatorLayout 中设置了 anchorView,则浮动操作按钮不会随 Snackbar 一起浮动 - Floating Action Button Not Floating With Snackbar If anchorView set within CoordinatorLayout 浮动操作按钮不会停留在SnackBar的顶部 - Floating Action Button won't stay on top of SnackBar Snackbar 通过片段导航重叠浮动操作按钮 - Snackbar Overlapping Floating Action Button Through Fragment Navigation Android底部工作表,带有带有Snackbar问题的浮动操作按钮 - Android Bottom Sheet with Floating Action Button with Snackbar Issue 上下移动浮动操作按钮以避免被快餐栏阻挡 - Moving Floating Action Button up and down to avoid getting blocked by a snackbar 当snackbar animation 开始时浮动动作按钮上下跳跃 - Floating Action Button jumps up and down when snackbar animation begins
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM