我终于找到了解决问题的方法.
对话框的创建:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
if (!hasTitle()) {
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}
if (position != null) {
WindowManager.LayoutParams windowParams = dialog.getWindow().getAttributes();
windowParams.x = position.x;
windowParams.y = position.y;
dialog.getWindow().setAttributes(windowParams);
} else {
WindowManager.LayoutParams attrs = dialog.getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(hasTitle() ? Color.WHITE : Color.TRANSPARENT));
dialog.getWindow().setGravity(Gravity.TOP | Gravity.START);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
return dialog;
}
片段的创建(我自定义对话框的样式 – 使用No_FRAME非常重要):
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// We customize the style of this dialog - we remove the frames of the dialogs and leave the drawing to the
// onCreateView() method, and we use the custom theme for dialogs - this is a special theme which has no
// Background and the status bar is left unchanged
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.Theme_Dialog);
}
自定义主题(我重用我的所有样式,以便对话框看起来相同):
@android:color/transparent
@color/transparent
现在我的对话框片段看起来像是全屏幕,当打开软键盘时它不再调整大小,从而在手动改变它的大小时产生闪烁效果.
重要的是DialogFragment.STYLE_NO_FRAME.
我希望这能帮助其他有类似问题的人.