首页 > 解决方案 > 选择文本时展开带有 EditText 的对话框

问题描述

我正在尝试使用 EditText 打开自定义对话框。

该对话框起初可以正确显示,但当用户选择文本时会显示奇怪的行为。

正常状态: 在此输入图片描述

用户选择文本时的状态: 在此处输入图像描述

我的 Java 代码:

AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AlertDialogStyle);
LayoutInflater inflater = activity.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.dialog_edit_description, null);

builder
        .setView(dialogView)
        .setPositiveButton("OK", (dialogInterface, i) -> {

        })
        .setNegativeButton("Abbrechen", (dialogInterface, i) -> {

        });


Dialog dialog = builder.create();
dialog.show();

我的布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@color/color4"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:text="Beschreibung bearbeiten"
    android:textStyle="bold"
    android:textSize="20sp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginTop="16dp"
    android:textAppearance="@style/AlertDialogStyle"
    android:textColor="@color/colorWhite"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<EditText
    android:id="@+id/descr_edit_text"
    android:inputType="text"
    android:hint="Beschreibung hinzufügen"
    android:layout_width="match_parent"
    android:longClickable="false"
    android:layout_height="wrap_content"
    android:textColorHint="@color/colorLightGrey3"
    android:textColor="@color/colorWhite"
    android:textAppearance="@style/myFont"
    android:layout_marginTop="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="4dp" />
</LinearLayout>

标签: androidandroid-dialog

解决方案


推荐阅读