AutoCompleteTextView android:dropDownSelector不工作

时间:2014-04-28 14:00:51

标签: android android-listview textview

我正在尝试为我的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>

auto_complete_text:

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

2 个答案:

答案 0 :(得分:1)

该人here说了一些对我有用的东西,即从你的适配器列表项中删除背景颜色,并将所需的背景颜色设置为DropDownBackgroundResource

但是我发现你没有XML格式的背景,请尝试将列表项android:background设置为具有常规背景颜色和不同颜色的选择器。

答案 1 :(得分:0)

你需要看看你的方法getView是否你的xml没有覆盖你的android:dropDownSelector

@Override
public View getView(int position, View convertView, ViewGroup parent) {
     View container = convertView;
      container = layoutInflater.inflate(R.layout.custom_view, parent, false);

}

custom_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/gray_color">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_centerVertical="true"
    android:layout_marginLeft="8dp"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="@android:color/white"
    android:text="@string/loading" />

</RelativeLayout>