【问题标题】:Alert dialog view is set incorrectly警报对话框视图设置不正确
【发布时间】:2019-01-27 01:30:09
【问题描述】:

我有一个警告对话框,EditText 包裹在 TextInputLayout 中。以下工作正常

builder.setView(R.layout.input_dialog)

但由于我想获得对编辑文本的引用,所以当我尝试以下操作时,TextInputLayout 消失了,只剩下编辑文本。我做错了什么?

val input = LayoutInflater.from(this).inflate(R.layout.input_dialog, null)
builder.setView(input)

input_dialog.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        app:hintEnabled="false"
        android:textColorHint="@android:color/darker_gray">

        <EditText
            android:id="@+id/input_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textNoSuggestions"
            android:textColor="@android:color/black"
            android:textSize="16dp" />
    </android.support.design.widget.TextInputLayout>

</LinearLayout>

活动

val builder = AlertDialog.Builder(this, android.R.style.Theme_Material_Light_Dialog_Alert)

【问题讨论】:

  • 什么是input_dialog_single
  • 打错字了,抱歉不是问题
  • 尝试在 inflate 方法中将布局的根添加为视图组,而不是 null ..
  • @AalapPatel,活动或对话框的根布局?如何获得它
  • 活动的根,在你的activity.xml中,给根布局ID并在这里使用它,看看会发生什么,我也想知道这个编辑文本没有出现或者你没有关注它 ??即如果你点击那里你看不到编辑文本焦点.. ???

标签: android kotlin android-edittext android-alertdialog


【解决方案1】:

我猜你需要将R.layout.input_dialog_single 更改为R.layout.input_dialog

【讨论】:

  • 打错字了,抱歉。这不是问题
【解决方案2】:

我发现一旦我删除 TextInputLayout 并只留下 EditText,一切正常。出于某种原因,TextInputLayout 在警报对话框中似乎无法正常工作。

【讨论】:

    猜你喜欢
    • 2013-03-09
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 2021-01-06
    相关资源
    最近更新 更多