【问题标题】:Dialog is not adjustable or resizable when keypad is raised抬起键盘时,对话框不可调整或调整大小
【发布时间】:2013-09-19 08:45:05
【问题描述】:

我有一个对话框,其中显示了一些字段。对话框填满整个屏幕。但是当键盘抬起时,它没有被调整或调整大小。

请看这张图片,

我已经在我的代码和 style.xml 文件中指定了但没有用。如何用键盘调整锅?如果是这种情况,用户将感到沮丧。

这是我的代码,

  final Dialog dialog = new Dialog(this,R.style.Theme_MyDialog);
    dialog.setTitle("Enter Details");
   dialog.setContentView(view);
 dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    dialog.show();

这是我的 style.xml 代码,

 <style name="Theme.MyDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowSoftInputMode">adjustResize|adjustPan</item>
 </style>

请帮我解决这个问题。 感谢您的帮助!

【问题讨论】:

    标签: android dialog resizable keypad adjustable


    【解决方案1】:

    'adjustPan' 不应在 style.xml 中使用,并且 contentView 的高度不应使用精确大小。可以使用以下代码:

        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
    
        // set width,height by density and gravity
        float density = getDensity(context);
        params.width = (int) (width * density);
        params.height = LayoutParams.FILL_PARENT;
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 2023-04-01
      • 1970-01-01
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多