23

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

Antrromet
  • 15,294
  • 10
  • 60
  • 75

10 Answers10

15

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...

Sami Eltamawy
  • 9,874
  • 8
  • 48
  • 66
R.daneel.olivaw
  • 2,681
  • 21
  • 31
  • 5
    This answer wouldn't really help if those links broke. It's worth updating the answer to include details of the linked solution. – Rudi Kershaw Mar 18 '14 at 16:17
13

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.

amol khedkar
  • 141
  • 1
  • 3
  • This is the wrong answer. getBaseContext() can cause a memory leak and getApplicationContext() WILL cause a leak. – Stimsoni Jan 05 '17 at 06:12
9

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.

Sami Eltamawy
  • 9,874
  • 8
  • 48
  • 66
  • @Amaresh I tried it by myself .. make sure you are using the previous snippet correctly .. and If you still have a problem with it, share your code, so we can try to figure out the problem together :) – Sami Eltamawy Sep 21 '15 at 20:24
3

You can use simple_list_item_1 in ArrayAdapter,

ArrayAdapter<String> autoadapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,cities);
            city = (AutoCompleteTextView) findViewById(R.id.location);

Another solution is to quit the style in AndroidManifest.xml

NOTE: This solution does not work with lollipop OS versions

Sami Eltamawy
  • 9,874
  • 8
  • 48
  • 66
3

Well, we can't set the "suggestion text" color, but we can change its background! Just use android:popupBackground="YOUR_COLOR_HEX" as in this example:

<AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/autocompletetextview"
        android:layout_gravity="center_horizontal"
        android:hint=" ... "
        android:popupBackground="#000000"/>

Works also on Lollipop! ;)

Kurtis92
  • 710
  • 1
  • 12
  • 34
1

You should use

setTheme(android.R.style.Theme); before setContentView

It worked for me :)

Emre Koç
  • 1,343
  • 1
  • 25
  • 44
1

Set background color of pop up ascity.setDropDownBackgroundResource(R.color.indicator);

Dijish U.K
  • 159
  • 1
  • 22
1

if anyone still have the same issue

This worked for me

autocompleteF.setBackgroundColor(color.black);
Bouchra
  • 51
  • 5
0

Add this to your theme:

<item name="android:autoCompleteTextViewStyle">@style/Widget.AppCompat.AutoCompleteTextView</item>
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
anapsil
  • 206
  • 2
  • 4
0

This worked for me First use this before setContentView()

setTheme(android.R.style.TextAppearance_DeviceDefault_Medium_Inverse);

you have to change some colors in colors.xml in the values folder