[英]Catch dismissal of BottomSheetDialogFragment
Is there any way to catch the dismissal/cancel of a BottomSheetDialogFragment? 有没有办法解决BottomSheetDialogFragment的解雇/取消?
Bottom sheet class 底层课程
public class ContactDetailFragment extends BottomSheetDialogFragment
{
private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback()
{
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState)
{
if (newState == BottomSheetBehavior.STATE_HIDDEN)
{
dismiss();
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset)
{
}
};
@Override
public void setupDialog(Dialog dialog, int style)
{
super.setupDialog(dialog, style);
View contentView = View.inflate(getContext(), R.layout.fragment_contactdetail, null);
dialog.setContentView(contentView);
BottomSheetBehavior mBottomSheetBehavior = BottomSheetBehavior.from(((View) contentView.getParent()));
if (mBottomSheetBehavior != null)
{
mBottomSheetBehavior.setBottomSheetCallback(mBottomSheetBehaviorCallback);
mBottomSheetBehavior.setPeekHeight((int) DisplayUtils.dpToPixels(CONTACT_DETAIL_PEEK_HEIGHT, getResources().getDisplayMetrics()));
}
}
}
What I've tried that doesn't work 我尝试过的东西不起作用
setupDialog
adding either of dialog.setOnCancelListener();
在setupDialog
添加dialog.setOnCancelListener();
or dialog.setOnDismissListener();
或dialog.setOnDismissListener();
never gets triggered 永远不会被触发 onStateChanged
only gets triggered if the user drags the bottomsheet down passed the collapsed state, and there is no state for dismissed/cancelled 底部表格行为的onStateChanged
只有在用户拖动底部表格向下通过折叠状态时才会被触发,并且没有被解雇/取消的状态 ContactDetailFragment.getDialog().setOnCancelListener()
does not get triggered 通过使用ContactDetailFragment.getDialog().setOnCancelListener()
将相同的oncancel / ondismiss侦听器添加到BottomSheetDialogFragment的实例化中ContactDetailFragment.getDialog().setOnCancelListener()
不会被触发 Given that it's essentially a dialog fragment, there must be some way to catch the dismissal? 鉴于它本质上是一个对话片段,必须有一些方法来解决这个问题?
Found a simple solution. 找到了一个简单的解决 Using onDestroy
or onDetach
in the BottomSheetDialogFragment allows me to get the dismissal correctly 使用BottomSheetDialogFragment中的onDestroy
或onDetach
可以让我正确解雇
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.