Kotlin Android Studio-AlertDialog中的文本输入布局

Kotlin Android Studio-AlertDialog中的文本输入布局,android,android-appcompat,layout-inflater,Android,Android Appcompat,Layout Inflater,我需要将自定义布局充气到AlertDialog 这是我的代码: val inflater = LayoutInflater.from(applicationContext) val dialogView = inflater.inflate(R.layout.alertdialog_autocancel, autocancel_root) //Inflate layout for AlertDialog val alertDialogHour = AlertDi

我需要将自定义布局充气到AlertDialog

这是我的代码:

val inflater = LayoutInflater.from(applicationContext)
        val dialogView = inflater.inflate(R.layout.alertdialog_autocancel, autocancel_root) //Inflate layout for AlertDialog

        val alertDialogHour = AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle) //build AlertDialog

        alertDialogHour.setView(dialogView) //set inflated layout
一切正常,但当我添加到自定义布局时

<com.google.android.material.textfield.TextInputLayout
        android:layout_width="250dp"
        android:backgroundTint="#d37a7a"
        android:layout_marginTop="35dp"
        android:layout_height="wrap_content">
    <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:id="@+id/minute_editText"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:backgroundTint="#d37a7a"
            android:hint="@string/minute"
            android:fontFamily="@font/product_sans_regular"
            android:textColor="#ffffff"
            android:textColorHint="#ffffff"
            android:layout_height="wrap_content"
            android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>

}

请勿自行膨胀视图
AlertDialog.Builder
具有为布局本身充气的
setView(res:Int)
功能

示例:

AlertDialog.Builder(this)
            .setView(R.layout.alertdialog_autocancel)
            .create()

不要自己膨胀视野
AlertDialog.Builder
具有为布局本身充气的
setView(res:Int)
功能

示例:

AlertDialog.Builder(this)
            .setView(R.layout.alertdialog_autocancel)
            .create()

是否添加了材料组件依赖项?你能把你的build.gradle(应用程序)级别放在dependecy吗?我的主布局中还有两个TextInputLayout,它们工作得很好。不管怎样,我用我的dependenciesTry删除背景编辑了这个问题。你们添加了材料组件依赖项了吗?你能把你的build.gradle(应用程序)级别放在dependecy吗?我的主布局中还有两个TextInputLayout,它们工作得很好。无论如何,我用dependenciesTry删除BackgroundTint编辑了这个问题。如果我让构建器膨胀布局本身,我以后就无法在按钮的onClick()中获取输入值,因为我不知道应该在哪个视图上调用findViewById(输入)。我不反对夸大观点。AlertDialog.Builder的setView(视图视图)对我来说没有任何问题。如果我让生成器膨胀布局本身,我以后无法在按钮的onClick()中获取输入值,因为我不知道应该在哪个视图上调用findViewById(输入)。我不反对夸大观点。对于我来说,AlertDialog.Builder的setView(视图)可以正常工作。