Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-以编程方式设置后台选择器状态_Android_Android Selector_Android Background - Fatal编程技术网

Android-以编程方式设置后台选择器状态

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

我有一个包含EditText和ImageView的线性布局。我给EditText设置了@null背景,给LinearLayout设置了以下背景:

?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