情况:DialogFragment 在全面屏底部往往会出现一个问题(如下图)
问题图
解决方案:
@Override
public void onStart(){
super.onStart();
Window win = getDialog().getWindow();
DisplayMetrics dm =new DisplayMetrics();
win.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparent)));
getActivity().getWindowManager().getDefaultDisplay().getMetrics( dm );
win.setLayout( dm.widthPixels,dm.heightPixels );
// 一定要设置Background,如果不设置,window属性设置无效
WindowManager.LayoutParams params = win.getAttributes();
params.gravity = Gravity.BOTTOM;
// 使用ViewGroup.LayoutParams,以便Dialog 宽度充满整个屏幕
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
int v = win.getAttributes().flags;
// 全屏 66816 - 非全屏65792
if(v !=66816){//非全屏
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
}else{//取消全屏
params.height = dm.heightPixels;
}
win.setAttributes(params);
}