android - 如何更改 MaterialDesign EditText 中的提示?

标签 android kotlin android-edittext hint

我使用 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>

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

最佳答案

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

关于android - 如何更改 MaterialDesign EditText 中的提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57331680/

相关文章:

java - Android EditText setOnClickListener

android - 如果编辑文本已填充输入,请更改其下划线颜色?

java - 当我单击第二个 Activity 布局时,它没有启动

java - 删除 RealmObject 类

android - 如果应用程序未至少启动一次,则广播接收器无法在 ICS 中工作

kotlin - 在每个单元测试之前,如何将Hystrix断路器完全复位?

Android 不显示所有通知

c# - Unity Android 前置摄像头 WTF 错误

android - KotterKnife - 某些类不能使用 bindView(R.id.example_id)

android - 编辑文本价格