android - TextInputLayout 对在 EditText 中以编程方式给出提示无效

标签 android android-textinputlayout

我有一个 EditText,它的父级是 TextInputLayout。 我正在尝试以编程方式为 EditText 提供提示(不在布局中) 在这种情况下,文本输入提示动画不起作用,它就像简单的 EditText 一样工作。有人可以建议如何处理它。

下面是我的布局。

<android.support.design.widget.TextInputLayout
    android:id="@+id/text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/post_EditTextPostAnAd"
        style="@style/abc_EditView" />

</android.support.design.widget.TextInputLayout>

最佳答案

您必须将提示设置为 TextInputLayout 这是代码。

TextInputLayout textInputLayout = (TextInputLayout)findViewById(R.id.text_input_layout);
textInputLayout.setHint("Hello");

更新

在 Kotlin 中:

val textInputLayout = findViewById(R.id.text_input_layout)
textInputLayout.hint = "Hello"

关于android - TextInputLayout 对在 EditText 中以编程方式给出提示无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34198599/

相关文章:

android - Ti.media.showCamera 在 iPhone 上抛出 'undefined' 错误,但在 Android 上工作正常

android - 如何减少代码重复: TextInputLayout

android - 当输入超过 TextInputLayout 的 counterMaxLength 时出现 RuntimeException

Android SDK : how to solve setPasswordVisibilityToggleEnabled(boolean) is deprecated?

android - SharedTest 在 Android Studio Chipmunk 上收到警告 "Duplicate content root detected"

Android 使用多个线程池执行器

java - 使用 Parse 后端填充 TextView

android - 支持的最大图像尺寸是多少

Android - TextInputLayout 不包装 TextInputEditText 的提示