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