我这边试过还是不行,而且我们ui是要dialog不全屏的,下面附上代码
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
//设置点击外部可消失
dialog.setCanceledOnTouchOutside(true);
//设置使软键盘弹出的时候dialog不会被顶起
Window win = dialog.getWindow();
dialog.setOnKeyListener(this);
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
win.setSoftInputMode(params.SOFT_INPUT_ADJUST_NOTHING);
//这里设置dialog的进出动画
win.setWindowAnimations(R.style.DialogBottomAnim);
params.gravity = Gravity.BOTTOM;
// 使用ViewGroup.LayoutParams,以便Dialog 宽度充满整个屏幕
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setAttributes(params);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable());
final View view = getView();
view.post(new Runnable() {
@Override
public void run() {
View parent = (View) view.getParent();
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) (parent).getLayoutParams();
CoordinatorLayout.Behavior behavior = params.getBehavior();
BottomSheetBehavior mBottomSheetBehavior = (BottomSheetBehavior) behavior;
//设置高度
int height = Screen.getHeight(getContext()) - StatusBarUtil.getStatusBarHeight(getContext()) ;
mBottomSheetBehavior.setPeekHeight(height);
parent.setBackgroundColor(Color.TRANSPARENT);
}
});
}
}