Open BottomSheet DialogFragment in Expanded mode by default.

suggest change

A BottomSheetDialogFragment opens in STATE_COLLAPSED by default. It can be forced to STATE_EXPANDED, taking the full screen, with the following code:

@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;
}

The dialog animation is slightly noticeable, but the fragment opens full screen.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents