【发布时间】:2019-08-07 11:28:00
【问题描述】:
我在 TextInputLayout 中有一个 TextInputEditText。 我想根据 EditText 是否有焦点来更改 TextInputLayout 的背景。 我可以通过从活动中观察编辑文本的焦点来轻松实现这一点,然后相应地更新背景。 但是,如果我已经在使用数据绑定,那么从活动中更新元素似乎是一种浪费。 有没有办法从 EditText 内的焦点更改回调中引用 TextInputLayout 的背景?
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/input_field_unselected_background">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:inputType="text"
android:hint="@string/hint_placeholder"
android:background="@android:color/transparent"/>
</com.google.android.material.textfield.TextInputLayout>
【问题讨论】:
标签: android kotlin layout data-binding