Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoCompleteTextview Color set white by default

I used an AutoCompleteTextView in my android app and it is working correctly. The only problem I am facing is that the color of the suggestions is white by default that is i am not able to see any suggestions. So when i start typing something the list expands with white entries(invisible), but when i click on any item i find that it is working as it should be. Only the color seems to be the problem. I am using the following code.

<AutoCompleteTextView android:id="@+id/location"  android:textColor="#000000"
            android:layout_width="fill_parent" android:layout_height="wrap_content"></AutoCompleteTextView>

and

 ArrayAdapter<String> autoadapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,cities);
            city = (AutoCompleteTextView) findViewById(R.id.location);
            city.setAdapter(autoadapter);
            city.setThreshold(1);
            city.setTextColor(Color.BLACK);

Can anyone please tell me what the problem is??
-Thanks in advance

like image 803
Antrromet Avatar asked Dec 12 '11 06:12

Antrromet


3 Answers

This a logged bug,

You can find some ways to fix it in the same link.

Auto complete text view bug

Bug solution

Note: This solution will not work with lollipop

I hope it helps...

like image 90
R.daneel.olivaw Avatar answered Oct 17 '22 10:10

R.daneel.olivaw


I tried setting up the theme before setcontext, tried different resources parameter in arrayAdapter and tried different theme ,but nothing helped.

Then I changed the context from 'this' to 'getApplicationContext' but the problem was persistent.

Finally I changed the context parameter to "getBaseContext()" and the problem was solved.

like image 43
amol khedkar Avatar answered Oct 17 '22 11:10

amol khedkar


For Lollipop, all the work around solutions in the reported bug will not work.

I finally reached a solution that works with lollipop and the previous OS versions by using android.R.layout.simple_spinner_dropdown_item with the adapter instead as the following:

ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, suggestionList);

This will solve the White text issue without any need to change Theme attributes or anything.

like image 9
Sami Eltamawy Avatar answered Oct 17 '22 11:10

Sami Eltamawy