我正在尝试为我的 AutoCompleteTextView 自定义一个选择器,以便在选择它时颜色会发生变化。我正在实现 android:dropDownSelector
。但是它不起作用,我得到了默认值....
aAdapterAutoComplete = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.auto_complete_text, suggest);
autoComplete.setAdapter(aAdapterAutoComplete);
布局:
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
style="@style/autocomplete_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dropDownSelector="@drawable/autocomplete_selector"
android:hint="@string/type_here_to_search"
android:imeOptions="actionSearch"
android:textSize="@dimen/text_size" >
<requestFocus />
</AutoCompleteTextView>
自动完成文本:
<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="@dimen/serach_bar_padding_top"
android:textSize="@dimen/text_size"
android:textColor="@color/text_color"
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/auto_select_color" />
<item
android:drawable="@drawable/auto_focused_color" />
最佳答案
那个家伙 here说了一些对我有用的东西,那就是从你的适配器列表项中删除背景颜色,并将想要的背景颜色设置为 DropDownBackgroundResource
。
但我发现您的 XML 中没有背景,请尝试将列表项的 android:background
设置为具有常规背景色和按下的不同颜色的选择器。
关于android - AutoCompleteTextView 安卓 :dropDownSelector not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23343152/