{"id":2826,"date":"2014-02-21T17:07:23","date_gmt":"2014-02-21T17:07:23","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/21\/honeycomb-customize-searchview-inside-the-action-bar-collection-of-common-programming-errors\/"},"modified":"2014-02-21T17:07:23","modified_gmt":"2014-02-21T17:07:23","slug":"honeycomb-customize-searchview-inside-the-action-bar-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/02\/21\/honeycomb-customize-searchview-inside-the-action-bar-collection-of-common-programming-errors\/","title":{"rendered":"Honeycomb &#8211; customize SearchView inside the action bar-Collection of common programming errors"},"content":{"rendered":"<p>In case anyone wants to modify the views directly, here is how you can change the colors\/fonts\/images and customize the search box to your pleasure. It is wrapped in a try\/catch in case there are differences between versions or distributions, so it won&#8217;t crash the app if this fails.<\/p>\n<pre><code>        \/\/ SearchView structure as we currently understand it:\n        \/\/ 0 =&gt; linearlayout\n        \/\/      0 =&gt; textview (not sure what this does)\n        \/\/      1 =&gt; image view (the search icon before it's pressed)\n        \/\/      2 =&gt; linearlayout\n        \/\/           0 =&gt; linearlayout\n        \/\/               0 =&gt; ImageView (Search icon on the left of the search box)\n        \/\/               1 =&gt; SearchView$SearchAutoComplete (Object that controls the text, subclass of TextView)\n        \/\/               2 =&gt; ImageView (Cancel icon to the right of the text entry)\n        \/\/           1 =&gt; linearlayout\n        \/\/               0 =&gt; ImageView ('Go' icon to the right of cancel)\n        \/\/               1 =&gt; ImageView (not sure what this does)\n        try {\n            LinearLayout ll = (LinearLayout) searchView.getChildAt(0);\n            LinearLayout ll2 = (LinearLayout) ll.getChildAt(2);\n            LinearLayout ll3 = (LinearLayout) ll2.getChildAt(0);\n            LinearLayout ll4 = (LinearLayout) ll2.getChildAt(1);\n            TextView search_text = (TextView) ll3.getChildAt(1);\n            search_text.setTextColor(R.color.search_text);\n            ImageView cancel_icon = (ImageView)ll3.getChildAt(2);\n            ImageView accept_icon = (ImageView)ll4.getChildAt(0);\n            cancel_icon.setBackgroundDrawable(d);\n            accept_icon.setBackgroundDrawable(d);\n        } catch (Throwable e) {\n            Log.e(\"SearchBoxConstructor\", \"Unable to set the custom look of the search box\");\n        }\n<\/code><\/pre>\n<p>This example shows changing the text color and the background colors of the cancel\/accept images. searchView is a SearchView object already instantiated with it&#8217;s background color:<\/p>\n<pre><code>Drawable d = getResources().getDrawable(R.drawable.search_widget_background);\nsearchView.setBackgroundDrawable(d);\n<\/code><\/pre>\n<p>Here is the drawable code:<\/p>\n<pre><code>\n\n\n    \n\n\n<\/code><\/pre>\n<p>Obviously, this is hacky, but it will work for now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In case anyone wants to modify the views directly, here is how you can change the colors\/fonts\/images and customize the search box to your pleasure. It is wrapped in a try\/catch in case there are differences between versions or distributions, so it won&#8217;t crash the app if this fails. \/\/ SearchView structure as we currently [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2826","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2826"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2826\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}