【发布时间】:2017-10-03 18:47:07
【问题描述】:
在使用底页对话框片段时,它为底页对话框设置默认高度。在我的应用程序中,我想为底页对话框设置 80% 的高度。如何将 80% 的高度设置为底页对话框?
【问题讨论】:
-
展示你的作品。
标签: android bottom-sheet
在使用底页对话框片段时,它为底页对话框设置默认高度。在我的应用程序中,我想为底页对话框设置 80% 的高度。如何将 80% 的高度设置为底页对话框?
【问题讨论】:
标签: android bottom-sheet
试试下面的代码。
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();
【讨论】:
你可以这样做,它可以用你需要的任何高度替换 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>
【讨论】: