How to change search suggestions Text color

I want him to be in black. I tried changing the textPrimaryColor, but the search input field was also affected, and I don't want this to happen.

Screen shot

Here are my styles for the action bar.

<style name="MyActionBar" parent="Theme.AppCompat.Light"> <item name="android:textColorPrimary">@android:color/white</item> <item name="android:textColorPrimaryInverse">@android:color/white</item> <item name="android:textColorHint">@android:color/white</item> <item name="android:actionMenuTextColor">@android:color/white</item> <item name="android:textColorSecondary">@android:color/white</item> </style> 
+5
source share
2 answers

I had the same problem and found a solution here: https://code.google.com/p/android/issues/detail?id=5237#c8

EDIT:

Try overriding the style of the proposed text.

In your "MyActionBar" style, add the following element:

 <item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewLight</item> 

And create an AutoCompleteTextViewLight style that captures the color:

 <style name="AutoCompleteTextViewLight" parent="@android:style/Widget.AutoCompleteTextView"> <item name="android:textColor">@android:color/primary_text_light</item> </style> 
+4
source

I ran into this problem before and created a job for it.

 /** * @param viewGroup * View to search for child views inside * @param _class * child view class inside the View * @return child view of corresponding View class */ public static <V extends View> Collection<V> findChildrenByClass(ViewGroup viewGroup, Class<V> _class) { return gatherChildrenByClass(viewGroup, _class, new ArrayList<V>()); } /** * @param viewGroup * View to search for child views inside * @param _class * child view class inside the View * @param childrenFound * child view if found * @return child view of corresponding View class */ @SuppressWarnings("unchecked") private static <V extends View> Collection<V> gatherChildrenByClass(ViewGroup viewGroup, Class<V> _class, Collection<V> childrenFound) { for (int i = 0; i < viewGroup.getChildCount(); i++) { final View child = viewGroup.getChildAt(i); if (_class.isAssignableFrom(child.getClass())) { childrenFound.add((V)child); // unchecked on this line } if (child instanceof ViewGroup) { gatherChildrenByClass((ViewGroup) child, _class, childrenFound); } } return childrenFound; } 

Here are two methods that find all SearchView child views; there are currently three children for SearchView :

  • TextView , which can be seen in the drop-down list
  • AutoCompleteTextView that you enter inside SearchView
  • ImageView , which is a close image to the right of SearchView

Now find the TextView , and then change its color. Do this in an Activity or Fragment :

 // Setting up the TextView of searchView suggestions drop down list for (TextView textView : findChildrenByClass(mSearchView, TextView.class)) { textView.setHint("Type a word"); textView.setTextColor(Color.rgb(255, 255, 255)); textView.setHintTextColor(Color.argb(128, 255, 255, 255)); } 

Done:)

0
source

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


All Articles