使用bottomsheet对话框片段时,它为底部对话框设置默认高度。在我的应用程序中,我想为底部对话框设置80%的高度。如何在底部对话框中设置80%的高度?
答案 0 :(得分:8)
请尝试以下代码。
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();
答案 1 :(得分:-1)
您可以执行此操作,以您需要的任何高度替换600dp
<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>