set the font style and size in a SearchView  [ 797 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 static  Collection 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...

#sidebar a { color:#fff; } #sidebar ul ul li { color: #DEF585; } #sidebar h2 { color: #fff; } #sidebar ul p, #sidebar ul select { color: #BEDDBE; } #backfly { background: url(images/golfBallWallPaper.jpg) left bottom fixed repeat-x #65a51d; }