I ran into this problem before and created a job for it.
public static <V extends View> Collection<V> findChildrenByClass(ViewGroup viewGroup, Class<V> _class) { return gatherChildrenByClass(viewGroup, _class, new ArrayList<V>()); } @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);
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 listAutoCompleteTextView that you enter inside SearchViewImageView , 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:)
source share