【问题标题】:DialogFragment is not going up when soft keyboard is on打开软键盘时,DialogFragment 不会上升
【发布时间】:2016-12-21 09:40:18
【问题描述】:

我在应用程序的其他地方有对话框,它们工作得很好(键盘不会隐藏视图),但是在我写的这个特殊的新对话框中,当键盘打开时它不会向上移动视图。我不知道为什么..

我的对话框布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:id="@+id/MyLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="15dp"
    android:background="@drawable/dialog_background"
    android:clickable="true"
    android:orientation="vertical"
    custom:maxHeight="@dimen/dialog_max_height"
    custom:maxWidth="@dimen/dialog_max_width" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="10dp"
        android:gravity="center"
        android:text="something" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/SomeEditText"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:minHeight="100dp"
            android:layout_margin="15dp"
            android:background="#ffffff"
            android:gravity="right|top"
            android:inputType="textMultiLine"
            android:singleLine="false"
            android:textColor="@color/edit_text_text_color"
            android:textSize="16dp" />

    </LinearLayout>

    <Button
        android:id="@+id/SomeButton"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dialog_button_height"
        android:layout_margin="15dp"
        android:text="text" />

</LinearLayout>

我有

android:windowSoftInputMode="adjustPan" > 

在我的清单中设置。

【问题讨论】:

  • 显示你的清单文件。
  • 我有android:windowSoftInputMode="adjustPan" 。但它在应用程序的其他对话框中工作得很好,所以我认为这与它没有任何关系。我也尝试了adjustResize,但没有帮助
  • 在清单中的活动中尝试此属性android:windowSoftInputMode="adjustResize"
  • 我写过我试过了,但不幸的是没有帮助

标签: android layout view keyboard


【解决方案1】:

找到解决办法:

我输入:getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

在 onCreateDialog 回调中

【讨论】:

  • 我认为应该是 "WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN" 以防止 UI 崩溃。
【解决方案2】:

我也遇到了同样的问题,并通过保留 getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) 来解决 在oncreateview里面

【讨论】:

    猜你喜欢
    • 2016-10-11
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 1970-01-01
    • 2020-11-04
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多