我使用以下代码显示 BottomSheetDialogFragment:
BottomSheetDialogFragment bottomSheetDialogFragment = new MediaAddFragment();
bottomSheetDialogFragment.show(getActivity().getSupportFragmentManager(), bottomSheetDialogFragment.getTag());
getActivity().getSupportFragmentManager().executePendingTransactions();
bottomSheetDialogFragment.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
onResume();
MainActivity.updateMediaButtons();
}
});
Run Code Online (Sandbox Code Playgroud)
要关闭它,我从 Fragment 中调用 Dismiss() 。这样,它就会被关闭,但如果应用程序恢复,它会再次显示,这不是我的意图。
如果有人能帮助我解决这个问题,我会很高兴。我已经扫描了有关如何正确使用这些 BottomSheetDialogFragments 的各种教程,但我找不到我的错误。
顺便说一句,我在 onResume 中没有任何代码来测试它。