1

I am trying to customize a selector for my AutoCompleteTextView so that when it is selected the color changes using. I am implementing android:dropDownSelector. However it is not working and I get the default value....

aAdapterAutoComplete = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.auto_complete_text, suggest);
autoComplete.setAdapter(aAdapterAutoComplete);

layout:

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

user1163234
  • 2,407
  • 6
  • 35
  • 63

2 Answers2

1

The guy here said something that worked for me, which is to remove the background color from you adapter list-item, and set the wanted background color as the DropDownBackgroundResource.

But I see that you have no background in you XML, try setting the list-item's android:background to a selector with a regular background color and a pressed different color.

Community
  • 1
  • 1
0

you need see if your adapter on method getView your xml not overriding your 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>
sphairo
  • 11
  • 4