android dialogfragment 焦点,android – 打开软键盘时始终调整DialogFragment的大小

我终于找到了解决问题的方法.

对话框的创建:

@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.

我希望这能帮助其他有类似问题的人.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值