Home » Android » android – How to change the default height of bottomsheet dialog fragment?

android – How to change the default height of bottomsheet dialog fragment?

Posted by: admin June 15, 2020 Leave a comment

Questions:

While using bottomsheet dialog fragment it set default height for bottomsheet dialog. In my application I want to set 80% height for bottomsheet dialog. How can I set 80% height to bottomsheet dialog?

How to&Answers:

Try this following code.

super.setupDialog(dialog, style);

View contentView = View.inflate(getContext(), R.layout.activity_device_nfclocation, null);

DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();

int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;

int maxHeight = (int) (height*0.88);

BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View) contentView.getParent());
mBehavior.setPeekHeight(maxHeight);
dialog.show();