Skip to content Skip to sidebar Skip to footer

How Can I Hide The Back Button In Searchview

Does anyone know how to hide the back button in AppCompat v21 searchview? (outlined by green line) I've searched a lot but couldn't find anything useful. menu_main.xml:

Solution 1:

changed app:showAsAction="always|collapseActionView" to app:showAsAction="always"

Solution 2:

Use the method:

getSupportActionBar().setDisplayHomeAsUpEnabled(false);

in order to remove the home button from the action bar.

Solution 3:

It's not perfectly safe method because back button (navigation up) doesn't have id. But if you are using AppCompat with Toolbar, you can use this code to find it. It should be the first in the layout.

intcount=this.getToolbar().getChildCount();

    for(inti=0; i < count; ++i) {
        Viewv=this.getToolbar().getChildAt(i);
        if(v instanceof ImageButton) {
            return (ImageButton)v;
        }
    }

Call this method inside onPrepareOptionsMenu if you want to change drawable of that button.

Post a Comment for "How Can I Hide The Back Button In Searchview"