默认情况下,在 Expanded 模式下打开 BottomSheet DialogFragment

BottomSheet DialogFragment 默认在 STATE_COLLAPSED 中打开。借助以下代码模板,可以强制打开 STATE_EXPANDED 并占用整个设备屏幕。

@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState){

    BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            BottomSheetDialog d = (BottomSheetDialog) dialog;

            FrameLayout bottomSheet = (FrameLayout) d.findViewById(android.support.design.R.id.design_bottom_sheet);
            BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
        }
    });

    // Do something with your dialog like setContentView() or whatever
    return dialog;
}

尽管对话框动画略显引人注目,但完成了全屏打开 DialogFragment 的任务。