Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Items in the drop down list of AutoCompleteTextView are not visible. How to change their color..?

I have made an AutoCompletetextView. The items in the dropdown of AutoCompleteTextView are not visible. How to change the color of of those items.

This is how it looks:

enter image description here

like image 627
Vipul J Avatar asked Jul 11 '12 07:07

Vipul J


3 Answers

For controlling the way you display items in your autocomplete view, you have to set the textViewResourceId in your adapter. You can use the ArrayAdapter and give android.R.layout.simple_dropdown_item_1line as the textViewResourceId as shown below.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, yourList);
AutoCompleteTextView autocompleteView = (AutoCompleteTextView) findViewById(R.id.autocomplete_box);
autocompleteView.setAdapter(adapter);

OR

if you want to create your own style for the items displayed, please create an XML with TextView as the root element like this (lets name it my_custom_dropdown.xml with black color text and white background)

<?xml version="1.0" encoding="utf-8"?>
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:textSize="20sp" 
    android:padding="5sp"
    android:textColor="@color/black"
    android:background="@color/white"/>

Then refer to the xml in your adapter as below -

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.my_custom_dropdown, yourList);
like image 68
Mukul Jain Avatar answered Nov 11 '22 04:11

Mukul Jain


Just to point out that by using android.R.layout.simple_dropdown_item_1line it will give you the same issue you encountered above. So you're better off just creating your own TextView in an .xml file.

like image 33
janex Avatar answered Nov 11 '22 04:11

janex


If changing code from "android.R.layout.simple_list_item_1" to "android.R.layout.simple_dropdown_item_1line" didn't work for you,

you should try to write this code before setContentView

setTheme(android.R.style.Theme);

It worked for me :)

like image 5
Emre Koç Avatar answered Nov 11 '22 04:11

Emre Koç