Quick Tip: Android Change Action Bar SearchView Hint (Placeholder) and Text Color

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:

int searchSrcTextId = getResources().getIdentifier("android:id/search_src_text", null, null);
EditText searchEditText = (EditText) searchView.findViewById(searchSrcTextId);
searchEditText.setTextColor(Color.BLUE); // set the text color
searchEditText.setHintTextColor(Color.BLUE); // set the hint color

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

SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

If it is in the Activity’s (or Fragment’s) content layout then just use the findViewById() method to get the view with the given ID.

Efficient Android Threading - I highly recommend this book if you want to learn how various components of the Android framework works. You'll learn a ton about Android internals and components like AsyncTask, Services, Broadcast Receivers, Executor Framework, Inter-Process Communication, etc. It also covers various OS internal topics like threads, processes, kernel and how all those components work to execute an Android app. Must read!

Author: Rishabh

Rishabh is a full stack web and mobile developer from India. Follow me on Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *