title: Toolbar+SearchView+textSelection = bad position of text selection bar
body: <h2>Background</h2>
  
  <p>I'm trying to theme <a href="https://play.google.com/store/apps/details?id=com.lb.app_manager" rel="nofollow noreferrer"><strong>my app</strong></a> to have more material design look, and as such, I have a toolbar that's being set as the actionBar of the activity.</p>
  
  <p>I have a SearchView in it that allows to search items of the listView below.</p>
  
  <h2>The problem</h2>
  
  <p>Thing is, you can select the text in the SearchView (to copy, cut, etc...), yet when this happens, the toolbar gets the text-selection toolbar on top of it, making it and the text itself hidden:</p>
  
  <p>Before text selection:</p>
  
  <p><img src="https://i.stack.imgur.com/0pPPR.png" alt="enter image description here"></p>
  
  <p>After text selection:</p>
  
  <p><img src="https://i.stack.imgur.com/YMUMh.png" alt="enter image description here"></p>
  
  <h2>What I've tried</h2>
  
  <p>I tried to disable text selection using this code:</p>
  
  <pre><code>  final EditText searchTextView=(EditText)searchView.findViewById(R.id.search_src_text);
    if(searchTextView!=null&amp;&amp;VERSION.SDK_INT&gt;=VERSION_CODES.HONEYCOMB)
      searchTextView.setTextIsSelectable(false);
  </code></pre>
  
  <p>But it didn't do anything. I've also tried to search for how to listen for the even of text selection (so that I could set the toolbar a marginTop or something), but I didn't find it.</p>
  
  <p>The only thing that I have succeeded is using this code, which tells me when the text-selection toolbar appears (but not when it disappears) : </p>
  
  <pre><code>  searchTextView.setOnCreateContextMenuListener(new OnCreateContextMenuListener()
    {
    @Override
    public void onCreateContextMenu(final ContextMenu menu,final View v,final ContextMenuInfo menuInfo)
      {
      Log.d("AppLog","onCreateContextMenu");
      }
    });
  </code></pre>
  
  <p>This doesn't help. I can't even close the menu. I think it can't even help, as some devices might show something else instead of a toolbar (like on LG devices, where they have a small popup).</p>
  
  <h2>The code</h2>
  
  <p>The layout is basically a vertical LinearLayout, where the first item is the toolbar:</p>
  
  <pre><code>&lt;LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"&gt;
  
    &lt;android.support.v7.widget.Toolbar
      android:id="@+id/activity_app_list__toolbar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="?attr/colorPrimary"
      android:colorControlNormal="?attr/colorControlNormal"
      android:minHeight="?attr/actionBarSize"
      android:theme="?attr/actionBarTheme"
      tools:ignore="UnusedAttribute"/&gt;
    ...
  </code></pre>
  
  <p>The theme that's used is set to hide the normal action bar:</p>
  
  <pre><code>  &lt;style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"&gt;
      &lt;item name="windowActionBar"&gt;false&lt;/item&gt;
      &lt;item name="windowNoTitle"&gt;true&lt;/item&gt;
    ...
  </code></pre>
  
  <p>The action bar menu's XML is quite basic and has 3 action items, where the first one of them is the searchView:</p>
  
  <pre><code>&lt;item
      android:id="@+id/menuItem_search"
      android:icon="?attr/app_search_menu_icon"
      android:title="@string/search"
      app:actionViewClass="android.support.v7.widget.SearchView"
      app:showAsAction="always|collapseActionView"/&gt;
  </code></pre>
  
  <p>Handling the SearchView is done via a special class I've made that supports even old Android versions. This is the main function that handles the searchView :</p>
  
  <pre><code>  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public void init(final MenuItem searchMenuItem,final int hintResId,final OnQueryTextListener onQueryTextListener,final OnActionExpandListener onActionExpandListener)
      {
      this._searchMenuItem=searchMenuItem;
      if(_searchView==null)
        {
        _searchView=(SearchView)MenuItemCompat.getActionView(searchMenuItem);
        if(_searchView==null)
          {
          MenuItemCompat.setShowAsAction(searchMenuItem,MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW|MenuItem.SHOW_AS_ACTION_ALWAYS);
          MenuItemCompat.setActionView(searchMenuItem,_searchView=new SearchView(_context));
          }
        _searchView.setQueryHint(_context.getString(hintResId));
        if(VERSION.SDK_INT&lt;VERSION_CODES.HONEYCOMB)
          {
          final EditText searchTextView=(EditText)_searchView.findViewById(R.id.search_src_text);
          if(searchTextView!=null)
            {
            searchTextView.setScroller(new Scroller(_context));
            searchTextView.setMaxLines(1);
            searchTextView.setVerticalScrollBarEnabled(true);
            searchTextView.setMovementMethod(new ScrollingMovementMethod());
            final int searchTextColorResId=App.getResIdFromAttribute(_context,android.R.attr.textColorPrimary);
            if(searchTextColorResId!=0)
              searchTextView.setTextColor(_context.getResources().getColor(searchTextColorResId));
            else
              {
              // TODO workaround for some v2.3 devices that can't get the correct color. remove this when stopping the support for v2.3
              TextView searchBadge=(TextView)_searchView.findViewById(R.id.search_badge);
              if(searchBadge!=null)
                searchTextView.setTextColor(searchBadge.getTextColors());
              }
            }
          }
        _searchView.setOnQueryTextListener(onQueryTextListener);
        MenuItemCompat.setOnActionExpandListener(searchMenuItem,onActionExpandListener);
        }
      }
  </code></pre>
  
  <p>The function is called at the end of "onCreateOptionsMenu" of any activity/fragment that is supposed to have a searchView, for example:</p>
  
  <pre><code>    _searchHolder.init(menu.findItem(R.id.menuItem_search),R.string.search_for_apps,onQueryTextListener,onActionExpandListener);
  </code></pre>
  
  <h2>The question</h2>
  
  <p>How can I solve this issue? Obviously this has happened because the Toolbar is just a view, so the text-selection bar is shown on top of it, but is there any way to fix this?</p>
  
  <p>How do I avoid the extra toolbar become on top of the one I've used?</p>
  
  <p>Is there a way to support all devices in this regard?</p>
  
  <p>Looking at Google's apps, it seems that they usually don't use the official searchView, but one of their own. Only on Youtube it seems like the official one, but there it seems as if they also use the official actionBar (plus it has weird colors when selecting the text).</p>