Search code examples
androidandroid-studiosearchview

How to remove screen overlay from searchview in Android?


As the title states, I would like to know how to remove the screen overlay from the SearchView. It's a bit ugly and annoying. Plus it gets in the way. I'm using android.support.v7.widget.SearchView.

Here's what it looks like:

searchview overlay


Solution

  • I have done like below, and I get no any overlay.

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    
    MenuItem searchItem = menu.findItem(R.id.search_city);
    searchView = (SearchView) searchItem.getActionView();
    searchView.setQueryHint("Search View Hint");
    
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
    
        @Override
        public boolean onQueryTextChange(String newText) {
            //Log.e("onQueryTextChange", "called");
            return false;
        }
    
        @Override
        public boolean onQueryTextSubmit(String query) {
    
    
            // Do your task here
    
            return false;
        }
    
    });
    
    return true;
    }