@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
// Associate search configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.search).getActionView();
searchView.setQueryHint("Client/DOB/PPSN");
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
// Setting the textview default behaviour properties
int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView textView = (TextView) searchView.findViewById(id);
textView.setTextColor(Color.WHITE);
textView.setHintTextColor(Color.WHITE);
// Set the search plate color to white
int linlayId = getResources().getIdentifier("android:id/search_plate", null, null);
View view = searchView.findViewById(linlayId);
Drawable drawColor = getResources().getDrawable(R.drawable.searchcolor);
view.setBackground( drawColor );
return super.onCreateOptionsMenu(menu);
}
Now this is the xml file searchcolor.xml for changing the plate color of search bar
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape >
<solid android:color="#ffffff" />
</shape>
</item>
<!-- main color -->
<item android:bottom="1.5dp"
android:left="1.5dp"
android:right="1.5dp">
<shape >
<solid android:color="#2c4d8e" />
</shape>
</item>
<!-- draw another block to cut-off the left and right bars -->
<item android:bottom="10.0dp">
<shape >
<solid android:color="#2c4d8e" />
</shape>
</item>
</layer-list>
and menu/menu.xml for creating the search in action bar
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/search"
android:icon="@drawable/search"
android:showAsAction="ifRoom"
android:actionViewClass="android.widget.SearchView" />
</menu>