Android-以编程方式设置后台选择器状态
我有一个包含EditText和ImageView的线性布局。我给EditText设置了@null背景,给LinearLayout设置了以下背景:Android-以编程方式设置后台选择器状态,android,android-selector,android-background,Android,Android Selector,Android Background,我有一个包含EditText和ImageView的线性布局。我给EditText设置了@null背景,给LinearLayout设置了以下背景: ?android:attr/editTextBackground 让它看起来像是一个小部件。当EditText获得焦点/被选中时,我想更新线性布局的背景可绘制性,以显示整个内容已被选中 线性布局的我的布局XML: <LinearLayout android:id="@+id/search_plate" android:orien
?android:attr/editTextBackground
让它看起来像是一个小部件。当EditText获得焦点/被选中时,我想更新线性布局的背景可绘制性,以显示整个内容已被选中
线性布局的我的布局XML:
<LinearLayout
android:id="@+id/search_plate"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/editTextBackground">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/edit_text"
android:layout_weight="1"
android:background="@null"
android:height="36dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/image_view_close"
android:src="@drawable/ic_clear"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"/>
</LinearLayout>
除了使用聚焦状态集,我还尝试了以下方法:
ENABLED_FOCUSED_SELECTED_STATE_SET
FOCUSED_SELECTED_STATE_SET
ENABLED_SELECTED_STATE_SET
SELECTED_STATE_SET
上述任何一项似乎都不会将线性布局的背景更改为蓝色下划线。任何帮助都将不胜感激 似乎:已启用\u聚焦\u已选择\u窗口\u聚焦\u状态\u集起作用。。。如果有人能解释这一点,那就太好了
ENABLED_FOCUSED_SELECTED_STATE_SET
FOCUSED_SELECTED_STATE_SET
ENABLED_SELECTED_STATE_SET
SELECTED_STATE_SET