{"id":1711,"date":"2014-09-09T22:35:24","date_gmt":"2014-09-09T17:05:24","guid":{"rendered":"http:\/\/codetheory.in\/?p=1711"},"modified":"2014-09-09T22:54:24","modified_gmt":"2014-09-09T17:24:24","slug":"android-change-action-bar-searchview-hint-placeholder-and-text-color","status":"publish","type":"post","link":"https:\/\/codetheory.in\/android-change-action-bar-searchview-hint-placeholder-and-text-color\/","title":{"rendered":"Quick Tip: Android Change Action Bar SearchView Hint (Placeholder) and Text Color"},"content":{"rendered":"

There are times when you’ll want to change the hint (placeholder) color and the text color of a SearchView<\/a> widget<\/a>. Here’s a small snippet that’ll allow us to do it:<\/p>\n

<\/p>\n

\r\nint searchSrcTextId = getResources().getIdentifier("android:id\/search_src_text", null, null);\r\nEditText searchEditText = (EditText) searchView.findViewById(searchSrcTextId);\r\nsearchEditText.setTextColor(Color.BLUE); \/\/ set the text color\r\nsearchEditText.setHintTextColor(Color.BLUE); \/\/ set the hint color\r\n<\/pre>\n

Based on the placement of the SearchView<\/code>, the code to get the View<\/code> object will differ. If it’s in the action bar (menu) then this is what we’ll be doing in the onCreateOptionsMenu<\/code> method of the Activity or Fragment:<\/p>\n

\r\nSearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();\r\n<\/pre>\n

If it is in the Activity’s (or Fragment’s) content layout then just use the findViewById()<\/code> method to get the view with the given ID.<\/p>\n","protected":false},"excerpt":{"rendered":"

There are times when you’ll want to change the hint (placeholder) color and the text color of a SearchView widget. Here’s a small snippet that’ll allow us to do it:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121,40],"tags":[105,89],"_links":{"self":[{"href":"https:\/\/codetheory.in\/wp-json\/wp\/v2\/posts\/1711"}],"collection":[{"href":"https:\/\/codetheory.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codetheory.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codetheory.in\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codetheory.in\/wp-json\/wp\/v2\/comments?post=1711"}],"version-history":[{"count":4,"href":"https:\/\/codetheory.in\/wp-json\/wp\/v2\/posts\/1711\/revisions"}],"predecessor-version":[{"id":1715,"href":"https:\/\/codetheory.in\/wp-json\/wp\/v2\/posts\/1711\/revisions\/1715"}],"wp:attachment":[{"href":"https:\/\/codetheory.in\/wp-json\/wp\/v2\/media?parent=1711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codetheory.in\/wp-json\/wp\/v2\/categories?post=1711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codetheory.in\/wp-json\/wp\/v2\/tags?post=1711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}