6

I have one activity with action bar. Action bar contains search view. I don't want that back button which appears when search view is clicked. Is it possible to remove it or hide it? That back button is not visible until I click the search view. By the way the following line of code doesn't help.

getSupportActionBar().setDisplayHomeAsUpEnabled(false);

enter image description here

Menu resource

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/action_search"
    android:title=""
    app:showAsAction="always|collapseActionView"
    android:icon="@drawable/ic_action_search"
    app:actionViewClass="android.support.v7.widget.SearchView" />

</menu>
Egis
  • 5,081
  • 5
  • 39
  • 61
  • possible duplicate of [How to change the default icon on the SearchView, to be use in the action bar on Android?](http://stackoverflow.com/questions/10445760/how-to-change-the-default-icon-on-the-searchview-to-be-use-in-the-action-bar-on) – xenteros May 18 '15 at 20:41
  • 1
    @xenteros it is not a duplicate. Clearly this want to remove back button and the other want to change search icon. – Eduardo E.R. May 22 '17 at 07:28

2 Answers2

7

I have been dealing with a similar issue. To simply remove the arrow, I changed app:showAsAction="always|collapseActionView" to app:showAsAction="always". However, now I have a blank space instead of the arrow, which is an issue I have yet to resolve.

nivekgnay
  • 188
  • 1
  • 7
  • It doesn't hide anything and I have never had `collapseActionView` https://stackoverflow.com/questions/56410048/searchview-in-expanded-mode-doesnt-hide-all-action-bar-icons-starting-from-mars – user924 Jun 01 '19 at 20:52
4

We had the same problem and fixed it by setting the

app:collapseIcon

attribute in the toolbar.

<android.support.v7.widget.Toolbar
         android:id="@+id/toolbar"
         android:layout_width="match_parent"
         android:layout_height="@dimen/toolbarHeight"
         app:collapseIcon="@drawable/collapseBackIcon" />
Julian Horst
  • 805
  • 8
  • 15