Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Dialog to Bottom Sheet

I've an activity. After setting the Dialog Theme I'm able to make it as a Dialog. I want to make it as a BottomSheetDialog. I want the dialog to be seen as bottom sheet and not a simple dialog.

Is there any way to startActivity directly as a BottomSheet?

Any help will be appreciated.

like image 411
User_st Avatar asked Sep 19 '25 11:09

User_st


1 Answers

First convert:

AlertDialog dialog =
    new AlertDialog.Builder(getContext()).customView(R.layout.dialog_my_loads_finish, false)
        .show();

to:

View view = View.inflate(getActivity(), R.layout.dialog_my_loads_finish, null);
BottomSheetDialog dialog = new BottomSheetDialog(getActivity());
dialog.setContentView(view);

and if you want to set specific height for bottom sheet you have to change R.layout.dialog_my_load_finish root to CoordinateLayout and add id and app:layer_behavior to first child then:

 dialog.setOnShowListener(dialog2 -> {
  View bottomSheet = dialog.findViewById(R.id.dialog_question_confirm_ct);
  BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
  bottomSheetBehavior.setPeekHeight(bottomSheet.getHeight());
});

finally: dialog.show()

like image 116
Amir Ardalan Avatar answered Sep 22 '25 07:09

Amir Ardalan