So I have a searchView. When I click on the search icon, search view opens, keyboard pops up and the 1st "x" appears so when you type something up you can click "x" to delete what you typed up. That's fine. Looks like this:
Then you see now that "x" button brightens up and becomes white colored, and you click it to cancel the searchView. Looks like this:
Now the searchView is canceled, the keyboard hides and the Icon button takes the place of the "x" button again. Looks like this:
Here's my menu_main.xml file:
Here's my code:
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item= menu.findItem(menuSearch);
final SearchView searchView = (SearchView) item.getActionView();
searchView.onActionViewCollapsed();
return true;
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
View view = this.getCurrentFocus();
if(view != null){
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
return super.onOptionsItemSelected(item);
}
My question is, The 2nd photo "x" the one that becomes white to cancel the searchView, instead of it saying "x", I want it to say "cancel".Do I have to add something to menu_main.xml in android:""? Or is there some code I have to add in my MainActivity class?