【问题标题】:How change upper-hint in MaterialDesign EditText?如何更改 MaterialDesign EditText 中的上部提示?
【发布时间】:2019-12-11 09:19:36
【问题描述】:

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

我在 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>

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

【问题讨论】:

    标签: android kotlin android-edittext hint


    【解决方案1】:

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

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

    这当然是可能的。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2017-08-25
        • 1970-01-01
        • 2022-01-01
        • 2020-12-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多