打开键盘后滚动对话框

8

我有一些涉及EditText字段的对话框。当我想要填充一些EditText时,键盘会弹出,这样我就无法填充在上面的某些字段。我需要关闭键盘并点击上面的EditText。如何使我的对话框在键盘打开时可滚动,以避免关闭键盘?


将您的Layout添加到ScrollView中。 - M D
我已经做了,但是没有帮助... - HK.avdalyan
@G 请展示一下你的布局。 - M D
3个回答

11

尝试:

dialog.getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

0

XML(dialog_layout.xml):

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="10dp"
        android:elevation="5dp">

    </androidx.cardview.widget.CardView>

</androidx.core.widget.NestedScrollView>

Java:

final Dialog dialog = new Dialog(this);
            dialog.setContentView(R.layout.dialog_layout);
            dialog.setCanceledOnTouchOutside(false);
            Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    dialog.show();

0
在清单文件中的活动中添加windowSoftInputMode
<activity
...
    android:windowSoftInputMode="stateHidden|adjustResize">

这是一个对话框,而不是活动页面。 - HK.avdalyan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接