有什么方法可以捕获 BottomSheetDialogFragment 的解雇/取消?
底片类
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()));
}
}
}
我尝试过的不起作用
- 在
setupDialog
添加dialog.setOnCancelListener();
或dialog.setOnDismissListener();
永远不会被触发 - 仅当用户向下拖动底部表通过折叠状态时才会触发底部表行为
onStateChanged
,并且没有解除/取消状态 - 将相同的 oncancel/ondismiss 侦听器添加到 BottomSheetDialogFragment 的实例化中,使用
ContactDetailFragment.getDialog().setOnCancelListener()
不会被触发
鉴于它本质上是一个对话片段,必须有某种方法来捕捉解雇?