【问题标题】:Android floating label effect no working on TextInputLayout using databindingAndroid浮动标签效果在使用数据绑定的TextInputLayout上不起作用
【发布时间】:2017-09-29 10:35:57
【问题描述】:

如果您使用数据绑定设置提示,则提示不会浮动

<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"

有人解决了这个问题吗?

【问题讨论】:

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


【解决方案1】:

您必须在TextInputLayout 上设置hint 属性。

使用材质组件:

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

使用旧的支持库:

<android.support.design.widget.TextInputLayout
     android:hint="@{....}"

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

【讨论】:

    猜你喜欢
    • 2017-12-11
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    相关资源
    最近更新 更多