关闭Snackbar时,FloatingActionButton不会下降 [英] FloatingActionButton does not come down when dismissing Snackbar
本文介绍了关闭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屋!
查看全文