Up button in SearchView of android

94 Views Asked by At

I have added a search view in my android app by using "android.support.v7.widget.SearchView",but it is not displaying the up button when i click on it.It is howing the X button.How to get the up button?

I am getting this image enter image description here

but i want the below image which has an up button when click on the search view and on click of up button search view should close enter image description here

1

There are 1 best solutions below

0
Mr Code On

See you can not have this home button thing in all version like the image you shared. But you can do few tricks for it.

  1. Check if you mobile version is lesser then Lollypop or not. If it is lesser, make a view similar to the image you shared at the bottom. And perform actions on it.
  2. If you are not intersted in making any view, then you have to use

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
      if ((keyCode == KeyEvent.KEYCODE_HOME) && webView.canGoBack()) {
        webView.goBack();
        return true;
      }
     return super.onKeyDown(keyCode, event);
    

    }