BottomSheetDialogFragment设置高度
BottomSheetDialogFragment设置高度
设置为屏幕百分比高度
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
View view = View.inflate(getContext(), R.layout.fragment_eos_pay_dialog, null);
// amount = view.findViewById(R.id.amount);
// pay_root = view.findViewById(R.id.pay_root);
dialog.setContentView(view);
dialog.getWindow().findViewById(R.id.design_bottom_sheet)
.setBackgroundResource(android.R.color.transparent);
mBehavior = BottomSheetBehavior.from((View) view.getParent());
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
int height = (int) (getResources().getDisplayMetrics().heightPixels * 0.6);//屏幕高的60%
layoutParams.height = height;
view.setLayoutParams(layoutParams);
return dialog;
}
设置固定高度
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
View view = View.inflate(getContext(), R.layout.fragment_eos_pay_resource_dialog, null);
dialog.setContentView(view);
dialog.getWindow().findViewById(R.id.design_bottom_sheet)
.setBackgroundResource(android.R.color.transparent);
mBehavior = BottomSheetBehavior.from((View) view.getParent());
mBehavior.setPeekHeight(dp2px(460));//高度为460dp
return dialog;
}
public static int dp2px(float dpValue) {
final float scale = getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}