set the font style and size in a SearchView [ 909 views ]
Goal: let’s customize a SearchView appearance
First of all the SearchView is a complex control. We need to find the child TextView to do this changes. Set the following style:
<item name="android:textSize">12dp</item> <item name="android:textStyle">italic</item>
here is the code:
for (TextView tv: findChildrenByClass(sv, TextView.class)) { tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); tv.setTypeface(null, Typeface.ITALIC); }
The findChildrenByClass function like this:
public staticCollection findChildrenByClass(ViewGroup viewGroup, Class clazz) { return gatherChildrenByClass(viewGroup, clazz, new ArrayList ()); } private static Collection gatherChildrenByClass(ViewGroup viewGroup, Class clazz, Collection 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; }
done...