Je voulais faire quelque chose de similaire. J'ai finalement dû trouver le TextView
parmi les SearchView
enfants:
for (TextView textView : findChildrenByClass(searchView, TextView.class)) {
textView.setTextColor(Color.WHITE);
}
Si vous voulez la méthode util:
public static <V extends View> Collection<V> findChildrenByClass(ViewGroup viewGroup, Class<V> clazz) {
return gatherChildrenByClass(viewGroup, clazz, new ArrayList<V>());
}
private static <V extends View> Collection<V> gatherChildrenByClass(ViewGroup viewGroup, Class<V> clazz, Collection<V> childrenFound) {
for (int i = 0; i < viewGroup.getChildCount(); i++)
{
final View child = viewGroup.getChildAt(i);
if (clazz.isAssignableFrom(child.getClass())) {
childrenFound.add((V)child);
}
if (child instanceof ViewGroup) {
gatherChildrenByClass((ViewGroup) child, clazz, childrenFound);
}
}
return childrenFound;
}