关闭Snackbar时,FloatingActionButton不会下降 [英] FloatingActionButton does not come down when dismissing Snackbar

查看:139
本文介绍了关闭Snackbar时,FloatingActionButton不会下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Snackbar.我有一个FloatingActionButton包裹在CoordinatorLayout中.显示Snackbar时,按钮将正确向上移动.自动关闭时,按钮向下移动.但是,如果我以编程方式关闭Snackbar,则该按钮不会下降.我的代码很简单:

I am trying to use a Snackbar. I have a FloatingActionButton wrapped in a CoordinatorLayout. When the Snackbar shows, the button is correctly moved up. When it dismisses automatically, the button moves down. But if I dismiss the Snackbar programmatically, the button does not go down. My code is simple:

mSnackbar = Snackbar.make(mCoordinatorLayout, text, Snackbar.LENGTH_LONG)
                .setAction(R.string.undo, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        undoDeleteTasks();
                    }
                });
        mSnackbar.show();

通过编程方式取消Snackbar时,是否可以使FloatingActionButton下移?

Is there a way to make the FloatingActionButton move down when the Snackbar is dismissed programmatically?

推荐答案

尝试一下:

Snackbar mysnack = Snackbar.make( fab, "Hi, welcome to my app!", Snackbar.LENGTH_LONG );
mysnack.getView().addOnAttachStateChangeListener( new View.OnAttachStateChangeListener() {
    @Override
    public void onViewAttachedToWindow( View v ) {

    }

    @Override
    public void onViewDetachedFromWindow( View v ) {
        fab.setTranslationY( 0 );
    }
});
mysnack.show();

这篇关于关闭Snackbar时,FloatingActionButton不会下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆