Android float 标签效果在使用数据绑定(bind)的TextInputLayout上不起作用

标签 android data-binding android-textinputlayout material-components-android

如果您使用数据绑定(bind)设置提示,则提示不会 float

<android.support.design.widget.TextInputLayout
    android:id="@+id/inputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="bottom"
    android:theme="@style/TextAppearance.TextInputLayout.Form"
    >

    <EditText
        android:id="@+id/usernameEditTxt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/default_margin_3"
        android:textSize="16sp"
        android:singleLine="true"
        android:hint="@{model.label}"
        android:inputType="none"
        />
</android.support.design.widget.TextInputLayout>

但是,如果您手动设置提示,它会起作用。
我正在使用 Android Studio 3.0
还使用 kapt "com.android.databinding:compiler:2.3.3"

有人解决了这个吗?

最佳答案

您必须设置 hint TextInputLayout 上的属性.

使用 Material 组件:

 <com.google.android.material.textfield.TextInputLayout
      android:hint="@{viewModel.textHint}"

使用旧的支持库:
<android.support.design.widget.TextInputLayout
     android:hint="@{....}"

原因是TextInputLayoutTextInputEditText 读取提示属性仅一次(如果未指定)。通货膨胀后TextInputEditText上的变化不要更改 TextInputLayout的提示。
使用 TextInputEditText 上的数据绑定(bind)您没有更新 TextInputLayout出于同样的原因。

关于Android float 标签效果在使用数据绑定(bind)的TextInputLayout上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46487021/

相关文章:

android - 如何解决 SurfaceHolder.setType 已弃用的问题?还有其他方法吗?

javascript - 将 Javascript 对象绑定(bind)到 HTML 元素

c# - 图像数据绑定(bind)到 pictureBox

data-binding - groovy swingbuilder 可绑定(bind)列表和表格

android - 与 ViewPager 一起使用时扩展 TextInputLayout 时出错

android - TextInputLayout 中的多行提示

android - 如何从广播接收器引用应用程序上下文

android - 适用于 Android 和 iPhone 的文本转语音库

android - 如何根据信号强度按升序对 getScanResults() 列表进行排序?

android - 使用TextInputLayout时出现gradle错误