How to customize AutoCompleteTextView dropdown on Android

17,699

Solution 1

I guess I figured it out, or rather what I was doing wrong. In a theme I put this:

<item name="android:autoCompleteTextViewStyle">@style/custom_autocomplete</item>

and the style is(or relevant part):

<item name="android:dropDownSelector">@drawable/custom_spinner</item>

and the custom_spinner is above.

Hope this can help someone.

Solution 2

In xml, for AutoCompleteTextView

android:dropDownSelector="@drawable/some_drawable"
Share:
17,699

Related videos on Youtube

kevinksmith
Author by

kevinksmith

Updated on June 04, 2022

Comments

  • kevinksmith
    kevinksmith almost 2 years

    I would like to know how, if it can be done, to customize the color of the dropdown from the AutoCompleteTextView when selected. I can customize everything else, but not the selected color ie - it stays the same.

    In the Activity:

    ArrayAdapter<String> adap = new ArrayAdapter<String>(this, R.layout.row, strings);
    autoNewBird = (AutoCompleteTextView)findViewById(R.id.autoCompleteBirdName);
    autoNewBird.setAdapter(adap);
    

    row.xml:

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/birdtext"
    android:padding="5dip"  
    android:background="@drawable/custom_spinner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    style="@style/spinner_item" 
    android:gravity="center_vertical"
    android:layout_gravity="center_vertical" android:lines="1"/>
    

    and the drawable custom_spinner.xml (in drawable folder)

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true"
    android:drawable="@drawable/listback" />
    <item android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/listback" />
    <item android:state_pressed="true" android:drawable="@drawable/threebythree" />
    <item android:state_enabled="true" android:state_focused="true"
    android:drawable="@drawable/threebythree" />              
    <item android:state_enabled="true" android:drawable="@drawable/listback" />
    <item android:state_focused="true" android:drawable="@drawable/listback" />
    <item android:drawable="@drawable/listback" />
    </selector>
    

    This works for a spinner dropdown, but for an AutoCompleteTextView, when selected, it does not change color like the spinner dropdown.

    Any help, or experience with this would be appreciated.

  • Sandra
    Sandra almost 11 years
    This is the right solution. For more clarification, the second line should go in style defined like this: <style name="custom_autocomplete" parent="@android:style/Widget.Holo.AutoCompleteTextView"></s‌​tyle>. Hope that helps:)
  • user1163234
    user1163234 almost 10 years
    Which layout are you using for the layout? I am doing like this aAdapterAutoComplete = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.auto_complete_text, suggest); autoComplete.setAdapter(aAdapterAutoComplete);
  • Mike6679
    Mike6679 over 8 years
    Only this worked for me. Adding: <item name="android:dropDownSelector">@drawable/custom_spinner</it‌​em> to my autocomplete style class did not work as not all attributes work in the style file and instead have to be added in the autocomplete definition in the xml layout.