How to change text color of popup text appcompat autocomplete?

I know that there are many questions with answers, but none of them work for me.

My styles and themes:

<style name="AnnaTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Colors, and stuff --> <item name="android:dropDownItemStyle">@style/DropDownItemStyle</item> <item name="android:spinnerDropDownItemStyle">@style/DropDownItemStyle</item> <item name="spinnerDropDownItemStyle">@style/DropDownItemStyle</item> </style> <style name="DropDownItemStyle" parent="Widget.AppCompat.Light.DropDownItem.Spinner"> <item name="android:textColor">@android:color/black</item> </style> 

But the result is still like this:

White dropdown

The layout is as follows:

 <android.support.design.widget.TextInputLayout android:id="@+id/til_email" android:layout_width="wrap_content" android:layout_height="wrap_content"> <AutoCompleteTextView android:id="@+id/et_email" android:layout_width="@dimen/join_field_width" android:layout_height="wrap_content" android:hint="@string/email" android:inputType="textEmailAddress"/> </android.support.design.widget.TextInputLayout> 

And adapter:

 emailView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Utils.getUniqueEmailsFromAccount(this))); 

Can you guys help me how to make the text black?

+5
source share
3 answers

Try this tip, then ...

First try changing the Adapter to this (if it doesn't work, try with the second option:

emailView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, Utils.getUniqueEmailsFromAccount(this)));


1 # Create a style like this:

 <style name="CustomAuto"> <item name="android:paddingTop">3dp</item> <item name="android:paddingRight">5dp</item> <item name="android:paddingBottom">3dp</item> <item name="android:paddingLeft">5dp</item> <item name="android:textColor">#000</item> </style> 

2 # Create a Layout as follows:

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/any_id" style="@style/CustomAuto" android:singleLine="true" /> 

3 # Change your Adapter to:

 emailView.setAdapter(new ArrayAdapter<>(this,R.layout.text_custom_view, Utils.getUniqueEmailsFromAccount(this))); 
+2
source

An easy solution is to create your own list item. So, create an XML layout file and write the following codes there.

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:textColor="@android:color/black" android:padding="5dp" android:layout_width="match_parent" android:singleLine="true" android:layout_height="wrap_content"/> 

And pass it to the adapter constructor.

 emailView.setAdapter(new ArrayAdapter<>(this, R.layout.that_layout, Utils.getUniqueEmailsFromAccount(this))); 
0
source

You can also override the adapter:

 emailView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Utils.getUniqueEmailsFromAccount(this))){ @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); TextView text = (TextView)view.findViewById(android.R.id.text1); text.setTextColor(Color.BLACK); return view; }}; 
0
source

Source: https://habr.com/ru/post/1235891/


All Articles