title: How to toggle androidx.SearchView search icon to back arrow
body: <p>I want to toggle button search with search icon to a back button with a back functionality and icon.</p>
  <p>I am using androidx searchView without a ToolBar to fulfill a product requirement, so OptionsMenu solutions are not applicable in my case</p>
  <pre><code>&lt;androidx.appcompat.widget.SearchView
              android:id=&quot;@+id/simpleSearchView&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;@dimen/search_bar_height&quot;
              android:layout_marginStart=&quot;@dimen/margin_small&quot;
              android:layout_marginEnd=&quot;@dimen/margin_small&quot;
              android:background=&quot;@drawable/rounded_edit_text&quot;
              android:queryBackground=&quot;@null&quot;
              android:iconifiedByDefault=&quot;false&quot;
              android:focusableInTouchMode=&quot;true&quot;
              app:searchIcon=&quot;@drawable/icon_search&quot;
              app:defaultQueryHint=&quot;@string/search&quot; /&gt;
  </code></pre>
  <p>Tried to change them through an XML selector but the icon disappears when the SearchView is focused</p>
  <p>here is my selector</p>
  <pre><code>&lt;selector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
      &lt;item android:drawable=&quot;@drawable/ic_search&quot; android:state_pressed=&quot;false&quot; /&gt;
      &lt;item android:drawable=&quot;@drawable/ic_search&quot; android:state_focused=&quot;false&quot; /&gt;
      &lt;item android:drawable=&quot;@android:drawable/ic_back&quot; /&gt;
  &lt;/selector&gt;
  </code></pre>
  <p>Also read the documents <a href="https://developer.android.com/reference/androidx/appcompat/widget/SearchView" rel="nofollow noreferrer">here</a> couldn't find a utility function to support my use case</p>
  <p>this is the image to when the SearchView is Focused and active, replace search with back button <a href="https://i.stack.imgur.com/8fO2d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8fO2d.png" alt="enter image description here" /></a></p>