title: SearchView in activity toolbar and filter to fragment
body: <p>I have given SearchView in activity with custom toolbar and filter data goes to fragment. When I click on the search icon,toolbar size increasing. Navigation bar is used in that activity,may be it is issue?.
  It is working with separate activity without navigation bar.vb</p>
  <p>Here is my code:
  <strong>Activity.xml :</strong></p>
  <pre><code>&lt;android.support.design.widget.AppBarLayout
  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;wrap_content&quot;
  app:elevation=&quot;5dp&quot;&gt;
  
  &lt;android.support.v7.widget.Toolbar
      android:id=&quot;@+id/toolbar&quot;
      style=&quot;@style/Toolbar&quot;
      app:contentInsetEnd=&quot;5dp&quot;
      app:contentInsetLeft=&quot;15dp&quot;
      app:contentInsetRight=&quot;5dp&quot;
      app:contentInsetStart=&quot;15dp&quot;
      app:theme=&quot;@style/AppTheme.Toolbar&quot;
      app:popupTheme=&quot;@style/AppTheme.PopupOverlay&quot;
      app:contentInsetStartWithNavigation=&quot;15dp&quot;
      app:titleTextColor=&quot;@color/colorWhite&quot;
      tools:targetApi=&quot;lollipop&quot;&gt;
  
      &lt;RelativeLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:orientation=&quot;horizontal&quot;&gt;
  
          &lt;TextView
              android:id=&quot;@+id/toolbar_title&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_alignParentLeft=&quot;true&quot;
              android:layout_alignParentStart=&quot;true&quot;
              android:layout_centerInParent=&quot;true&quot;
              android:layout_gravity=&quot;start&quot;
              android:gravity=&quot;center&quot;
              android:text=&quot;&quot;
              android:textAllCaps=&quot;false&quot;
              android:textColor=&quot;@color/colorWhite&quot;
              android:textSize=&quot;16sp&quot;
              android:textStyle=&quot;bold&quot;
              tools:ignore=&quot;RelativeOverlap&quot; /&gt;
  
  
          &lt;TextView
              android:id=&quot;@+id/toolbar_student_details&quot;
              android:layout_width=&quot;120dp&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_alignParentEnd=&quot;true&quot;
              android:layout_alignParentRight=&quot;true&quot;
              android:layout_gravity=&quot;end&quot;
              android:gravity=&quot;center&quot;
              android:text=&quot;&quot;
              android:textAllCaps=&quot;false&quot;
              android:textColor=&quot;@color/colorWhite&quot;
              android:textSize=&quot;16sp&quot;
              tools:ignore=&quot;RelativeOverlap&quot; /&gt;
  
          &lt;Spinner
              android:id=&quot;@+id/toolbar_student_details_spinner&quot;
              android:spinnerMode=&quot;dropdown&quot;
              android:layout_width=&quot;120dp&quot;
              android:backgroundTint=&quot;@color/colorWhite&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_alignParentEnd=&quot;true&quot;
              android:layout_alignParentRight=&quot;true&quot;
              android:layout_gravity=&quot;end&quot;
              android:textAllCaps=&quot;false&quot;
              android:textColor=&quot;@color/colorWhite&quot;
              android:textSize=&quot;16sp&quot;
              tools:ignore=&quot;RelativeOverlap&quot;
              android:visibility=&quot;gone&quot;
              &gt;
          &lt;/Spinner&gt;
  
          &lt;ImageView
              android:id=&quot;@+id/admin_image&quot;
              android:layout_width=&quot;30dp&quot;
              android:layout_height=&quot;30dp&quot;
              android:layout_alignParentEnd=&quot;true&quot;
              android:layout_alignParentRight=&quot;true&quot;
              android:layout_marginEnd=&quot;10dp&quot;
              android:layout_marginRight=&quot;10dp&quot;
              android:contentDescription=&quot;@string/app_name&quot;
              android:visibility=&quot;gone&quot; /&gt;
      &lt;/RelativeLayout&gt;
  
  
  &lt;/android.support.v7.widget.Toolbar&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  </code></pre>
  <p><strong>Fragament code:</strong></p>
  <pre><code>   @Override
     public View onCreateView(@NonNull LayoutInflater inflater, 
   ViewGroup 
  container, Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View rootView= 
         inflater.inflate(R.layout.fragment_staff_fragment_admin, 
              container, false);
      setHasOptionsMenu(true);
      ButterKnife.bind(this, rootView);
      return rootView;
  }
  
      @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  
      getBaseActivity().getMenuInflater().inflate(R.menu.menu_main, 
       menu);
      SearchView searchView;
      // Associate searchable configuration with the SearchView
      SearchManager searchManager = (SearchManager)getBaseActivity(). 
     getSystemService(Context.SEARCH_SERVICE);
      searchView = (SearchView) menu.findItem(R.id.action_search)
              .getActionView();
      assert searchManager != null;
      searchView.setSearchableInfo(searchManager
              .getSearchableInfo(getBaseActivity().getComponentName()));
      searchView.setMaxWidth(Integer.MAX_VALUE);
  
      // listening to search query text change
      searchView.setOnQueryTextListener(new 
       SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
              // filter recycler view when query submitted
              mAdapter.getFilter().filter(query);
              return false;
          }
  
          @Override
          public boolean onQueryTextChange(String query) {
              // filter recycler view when text is changed
              mAdapter.getFilter().filter(query);
              return false;
          }
      });
   }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_search) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Wo8aEl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wo8aEl.png" alt="enter image description here" /></a></p>