如何更改 MaterialDesign EditText 中的提示?

How change upper-hint in MaterialDesign EditText?

我使用 TextInputEditText 和科特林。我尝试以编程方式更改提示。但它只是在盒子里改变了。当我写东西时向上移动时添加 - 上面的提示没有显示。

我在 onCreate 中使用此代码:

editTextChooseDate.hint = "Please choose the Date"

然后我检查 editTextChooseDate 是否有一些测试并尝试通过以下方式更改提示:

 editTextChooseDate.hint = "Selected Date"

xml中有editTextChooseDate:

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/layoutEditTextChooseDate"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

    <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/editTextChooseDate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:maxLines="1"/>

</com.google.android.material.textfield.TextInputLayout>

我希望以编程方式更改上层提示。

确保您是在主线程上进行更改。

检查这个问题:programmatically set edit text hint in android?

当然有可能。

您应该将第二个 hint 设置为 layoutEditTextChooseDate 而不是 editTextChooseDate。因为你所说的 "upper-hint" 是父容器 TextInputLayout.

的一部分