{"id":847,"date":"2016-07-26T16:06:18","date_gmt":"2016-07-26T16:06:18","guid":{"rendered":"http:\/\/blog.silverterra.net\/?p=847"},"modified":"2016-07-26T16:15:53","modified_gmt":"2016-07-26T16:15:53","slug":"set-the-font-style-and-size-in-a-searchview","status":"publish","type":"post","link":"https:\/\/blog.silverterra.net\/?p=847","title":{"rendered":"set the font style and size in a SearchView"},"content":{"rendered":"<blockquote><p>Goal: let&#8217;s customize a SearchView appearance<\/p><\/blockquote>\n<p>First of all the SearchView is a complex control. We need to find the child TextView to do this changes. Set the following style:<\/p>\n<pre data-enlighter-language=\"xml\" class=\"EnlighterJSRAW\">\r\n  &lt;item name=&quot;android:textSize&quot;&gt;12dp&lt;\/item&gt;\r\n  &lt;item name=&quot;android:textStyle&quot;&gt;italic&lt;\/item&gt;\r\n<\/pre>\n<p>here is the code:<\/p>\n<pre data-enlighter-language=\"java\" class=\"EnlighterJSRAW\">\r\n  for (TextView tv: findChildrenByClass(sv, TextView.class)) {\r\n    tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);\r\n    tv.setTypeface(null, Typeface.ITALIC);\r\n  }\r\n<\/pre>\n<p>The <strong>findChildrenByClass<\/strong> function like this:<\/p>\n<pre>\r\n  public static <V extends View> Collection<V> findChildrenByClass(ViewGroup viewGroup, Class<V> clazz) {\r\n    return gatherChildrenByClass(viewGroup, clazz, new ArrayList<V>());\r\n  }\r\n\r\n  private static <V extends View> Collection<V> gatherChildrenByClass(ViewGroup viewGroup, Class<V> clazz, Collection<V> childrenFound) {\r\n    for (int i = 0; i < viewGroup.getChildCount(); i++) {\r\n      final View child = viewGroup.getChildAt(i);\r\n      if (clazz.isAssignableFrom(child.getClass())) { childrenFound.add((V)child); }\r\n      if (child instanceof ViewGroup) { gatherChildrenByClass((ViewGroup) child, clazz, childrenFound); }\r\n    }\r\n    return childrenFound;\r\n  }\r\n<\/pre>\n<p>done...<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Goal: let&#8217;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: here is the code: The findChildrenByClass function like this: public static Collection findChildrenByClass(ViewGroup viewGroup, Class clazz) { return gatherChildrenByClass(viewGroup, clazz, new ArrayList()); } private static [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-847","post","type-post","status-publish","format-standard","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=847"}],"version-history":[{"count":12,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/847\/revisions"}],"predecessor-version":[{"id":859,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/847\/revisions\/859"}],"wp:attachment":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}