Skip to content Skip to sidebar Skip to footer

Textcolor Of My Autocompletetextview Is Always White

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

Solution 1:

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

Solution 2:

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"?><TextViewxmlns: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" />

Solution 3:

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 :

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

Here is the custom layout file : item_drop_down

<?xml version="1.0" encoding="utf-8"?><TextViewxmlns: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 :)

Post a Comment for "Textcolor Of My Autocompletetextview Is Always White"