Reputation:
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?
Upvotes: 13
Views: 9858
Reputation: 134
you can do this it works replace 600dp by any height you need
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="bottomSheetDialogTheme">@style/CustomBottomSheet</item>
</style>
<style name="CustomBottomSheet"
parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/AppModalStyle</item>
</style>
<style name="AppModalStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="behavior_peekHeight">600dp</item>
</style>
Upvotes: -2
Reputation:
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();
Upvotes: 17