4

For some reason, no matter what I do the text coming up in my AutoCompleteTextView is always white. I've explicitly set textColor to black in my XML. I'm wondering if android.R.layout.simple_list_item_1 is white by default?

Here is where I set up my ArrayAdapter:

final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, strings);
                    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.searchUserTextField);
                    textView.setAdapter(adapter);

Here is my XML:

<AutoCompleteTextView
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:background="@drawable/edittext_border"
            android:layout_gravity="top"
            android:textColor="#000000"
            android:hint="@string/search_user"
            android:id="@+id/searchUserTextField"
            android:ems="150"
            android:paddingLeft="25dp"
            android:paddingTop="10dp"
            android:paddingRight="10dp"
            android:paddingBottom="10dp"
            android:maxLines ="4"
            android:maxLength ="150"
            android:scrollHorizontally="false"
            android:typeface="sans"
            android:textSize="14sp"
            android:fontFamily="sans-serif-light"
            android:capitalize="none"
            android:inputType="textEmailAddress"
            android:gravity="center_vertical"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_toLeftOf="@+id/submitSearch"
            android:layout_toStartOf="@+id/submitSearch" />
Martin Erlic
  • 5,467
  • 22
  • 81
  • 153
  • 1
    Does [this topic](http://stackoverflow.com/questions/8470804/autocompletetextview-color-set-white-by-default) help you? Try it! – diegocmaia Dec 16 '15 at 02:12
  • Try this one for the solution [enter link description here](http://stackoverflow.com/questions/11787057/autocompletetextview-background-foreground-color) – Kiran Kumar Dec 16 '15 at 04:13

3 Answers3

3

Looked like its a logged bug in AOSP. You can find some more information as well as workarounds in this post AutoCompleteTextview Color set white by default

Community
  • 1
  • 1
Charles Durham
  • 2,445
  • 16
  • 17
1

Just to add, in case someone is still looking for an answer that works as it is not a bug but you can provide your custom layout for autocomplete suggestions as follows:

Change this line of code

final ArrayAdapter<String> adapter = new ArrayAdapter<String (getApplicationContext(), android.R.layout.simple_list_item_1, strings);

to

final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.custom_autocomplete, strings);

Make a layout resource file as custom_autocomplete.xml and provide required settings. Working template

<?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="wrap_content"
        android:textColor="@color/colorPrimary"
        android:background="@color/white"
        android:paddingHorizontal="10dp"
        android:paddingVertical="15dp" />
Deven
  • 741
  • 1
  • 7
  • 21
0

Change the default layout for drop down item view to your own custom layout containing only TextView:

Example ( In Kotlin )-

Replace android.R.layout.select_dialog_item in the line:

val adapter: ArrayAdapter<String> = ArrayAdapter<String>(this, android.R.layout.select_dialog_item,gender)

To:

val adapter: ArrayAdapter<String> = ArrayAdapter<String>(this, R.layout.item_drop_down,gender)

where gender is :

private var gender :Array<String> = arrayOf("Male", "Female", "Others")

Here is the custom layout file : item_drop_down

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/appBlue"
android:gravity="center_vertical"
android:paddingStart="14dip"
android:paddingEnd="15dip"
android:ellipsize="marquee"
android:textSize="@dimen/sp_15"
/>

Hope this might help somebody! Happy Coding :)

Shivani Rastogi
  • 740
  • 7
  • 14