Android Bottom Sheets Modal bottom sheets with BottomSheetDialogFragment


You can realize a modal bottom sheets using a BottomSheetDialogFragment.

The BottomSheetDialogFragment is a modal bottom sheet.
This is a version of DialogFragment that shows a bottom sheet using BottomSheetDialog instead of a floating dialog.

Just define the fragment:

public class MyBottomSheetDialogFragment extends BottomSheetDialogFragment {

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return inflater.inflate(R.layout.my_fragment_bottom_sheet, container);

Then use this code to show the fragment:

MyBottomSheetDialogFragment mySheetDialog = new MyBottomSheetDialogFragment();
FragmentManager fm = getSupportFragmentManager();, "modalSheetDialog");

This Fragment will create a BottomSheetDialog.