Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SearchView Activity
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(, menu);
final MenuItem item = menu.findItem(;
if (item != null) {
final View actionView = item.getActionView();
if (actionView != null) {
SearchView searchView = (SearchView) actionView;
// changes the search icon
int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
final View v = searchView.findViewById(searchImgId);
if (v != null) {
ImageView vi = (ImageView) v;
// Changes the EditText style
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
View searchPlate = searchView.findViewById(searchPlateId);
if (searchPlate != null) {
SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final SearchableInfo searchableInfo = manager.getSearchableInfo(getComponentName());
searchView.setOnQueryTextListener((SearchView.OnQueryTextListener) fragment);
searchView.setOnCloseListener((SearchView.OnCloseListener) fragment);
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.