How to change the default height of bottomsheet dialog fragment?

百般思念 提交于 2019-12-10 03:50:12

问题


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?


回答1:


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();


来源:https://stackoverflow.com/questions/46551405/how-to-change-the-default-height-of-bottomsheet-dialog-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!