title: Handling the click on a SearchView's icon
body: <p>First, I will explain to you what I want to do. Then, I will show you what I've already done. Finally, I will ask for your help about what I will implement.</p>
  
  <h1>My aim</h1>
  
  <p>My aim is to have a <code>Toolbar</code> like the Playstore: <a href="https://i.stack.imgur.com/pH7II.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pH7II.jpg" alt="enter image description here"></a></p>
  
  <p>When you click on the burger menu, it displays the menu.
  When you click on the input, it displays changes the icon and it displays keyboard:</p>
  
  <p><a href="https://i.stack.imgur.com/NHBDu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NHBDu.png" alt="enter image description here"></a></p>
  
  <h1>What I have for now</h1>
  
  <p><a href="https://i.stack.imgur.com/3Jx8L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Jx8L.png" alt="enter image description here"></a></p>
  
  <p>I followed the documentation (<a href="https://developer.android.com/training/appbar/" rel="nofollow noreferrer">https://developer.android.com/training/appbar/</a> + <a href="https://developer.android.com/guide/topics/search/search-dialog" rel="nofollow noreferrer">https://developer.android.com/guide/topics/search/search-dialog</a> + <a href="https://developer.android.com/training/search/setup" rel="nofollow noreferrer">https://developer.android.com/training/search/setup</a>). Thus, I have:</p>
  
  <ol>
  <li><code>res/menu/action_bar_menu.xml</code> containing my <code>SearchView</code> widget</li>
  </ol>
  
  <pre class="lang-default prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
      &lt;item android:id="@+id/searchView"
          android:title="@string/search_title"
          app:actionViewClass="android.support.v7.widget.SearchView"
          app:showAsAction="always" /&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <ol start="2">
  <li>A <code>Toolbar</code> in my fragment's layout:</li>
  </ol>
  
  <pre class="lang-default prettyprint-override"><code>    &lt;android.support.v7.widget.Toolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:background="@color/colorRoyalRed"
      android:theme="@style/ToolbarStyle"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/&gt;
  </code></pre>
  
  <ol start="3">
  <li>The style <code>ToolbarStyle</code> (see above):</li>
  </ol>
  
  <pre class="lang-default prettyprint-override"><code>&lt;style name="ToolbarStyle"&gt;
      &lt;item name="android:background"&gt;@color/colorRoyalRed&lt;/item&gt;
      &lt;item name="android:textColorPrimary"&gt;@color/colorRichYellow&lt;/item&gt;
      &lt;item name="actionButtonStyle"&gt;@style/ToolbarActionButton&lt;/item&gt;
  &lt;/style&gt;
  &lt;style name="ToolbarActionButton"&gt;
      &lt;item name="android:padding"&gt;0dp&lt;/item&gt;
      &lt;item name="android:paddingStart"&gt;0dp&lt;/item&gt;
      &lt;item name="android:paddingEnd"&gt;0dp&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <ol start="4">
  <li>In the fragment class, I make use of the toolbar:</li>
  </ol>
  
  <pre class="lang-default prettyprint-override"><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_home, container, false);
      Toolbar toolbar = view.findViewById(R.id.toolbar);
      toolbar.setTitle("");
      AppCompatActivity app_compat_activity = (AppCompatActivity) getActivity();
      Objects.requireNonNull(app_compat_activity).setSupportActionBar(toolbar);
      app_compat_activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
  
      return view;
  }
  </code></pre>
  
  <ol start="5">
  <li>In the fragment class, I make use of the <code>SearchView</code>:</li>
  </ol>
  
  <pre class="lang-default prettyprint-override"><code>    @Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater menu_inflater) {
          menu_inflater.inflate(R.menu.action_bar_menu, menu);
          super.onCreateOptionsMenu(menu,menu_inflater);
  
          AppCompatActivity app_compat_activity = (AppCompatActivity) getActivity();
  
  
  SearchView search_view = (SearchView) menu.findItem(R.id.searchView).getActionView();
          search_view.setIconifiedByDefault(false);
          SearchManager search_manager = (SearchManager) Objects.requireNonNull(app_compat_activity).getSystemService(Context.SEARCH_SERVICE);
          search_view.setSearchableInfo(Objects.requireNonNull(search_manager).getSearchableInfo(app_compat_activity.getComponentName()));
      }
  </code></pre>
  
  <p>Well, there are other implementations (modifications concerning the manifest, etc.) but they are not important (note all the required changements to implement a simple search bar in the toolbar... more than 5 steps...).</p>
  
  <h1>What I would want to do next (help please!)</h1>
  
  <p><strong>I don't want to use anything other than the menu items structure (thus I don't want to actually add the <code>SearchView</code> in the fragment's layout).</strong></p>
  
  <ol>
  <li><p>How could I change the <code>SearchView</code>'s icon? For now it's a magnifying glass. It must be a burger menu. I tried to modify <code>res/menu/action_bar_menu.xml</code> by indicating a <code>android:icon=</code> to the <code>SearchView</code> but it didn't work. I also tried to use <code>&lt;item name="searchIcon"&gt;@drawable/ic_baseline_menu_24px&lt;/item&gt;</code> in the style <code>ToolbarActionButton</code> but it didn't work. <strong>Here the aim is to replace the glass by a burger menu icon.</strong></p></li>
  <li><p>How could I handle the click on the <code>SearchView</code>'s burger menu icon (once it will be set)? Indeed, I will call my <code>DrawerLayout::openDrawer</code> function to open my menu.</p></li>
  <li><p>How could I handle the click on the <code>SearchView</code>'s content? Indeed, I will replace the burger menu by the left arrow (and, if clicked, keyboard will disapear and the burger menu will be displayed).</p></li>
  </ol>
  
  <h1>Am I using the wrong things?</h1>
  
  <p>I just followed Google's documentation. But it seems so complicated to me to realize that I may be on the wrong path? Should I stop using the menu items structure?</p>