title: Can't control Android SearchView focus
body: <p>I have an activity with <code>SearchView</code> the problem I am having is </p>
  
  <p>1- I can't get focus when activity starts. I solved this by using <code>searchView.requestFocusFromTouch();</code> from <code>onCreateOptionsMenu()</code>. I thought this would be default because there is nothing else in this activity? Is this the right way to solve the problem?</p>
  
  <p>2- The real problem is I am using zxing <code>IntentIntegrator</code> and I want to hide the <code>@+id/coordinator_layout</code> when I return from scanner and search is in progress. </p>
  
  <p>I start scanner with this code and <code>onActivityResult()</code> I start the <code>AsyncTask</code></p>
  
  <pre><code>    IntentIntegrator integrator = new IntentIntegrator(this);
      integrator.setCaptureActivity(BarcodeScannerActivity.class);
      integrator.initiateScan();
  </code></pre>
  
  <p>But when I set <code>R.id.coordinator_layout</code> visibility to GONE or INVISIBLE inside <code>AsyncTask</code>, immediately SearchView gets focus. This happens only after returning from a barcode scanner activity and running <code>AsyncTask</code> with following code in <code>onPreExecute()</code></p>
  
  <pre><code>    CoordinatorLayout coordinatorLayout = activity.findViewById(R.id.coordinator_layout);
      coordinatorLayout.setVisibility(View.GONE);
  </code></pre>
  
  <p>then focus goes to <code>SearchView</code> and softkeyboard pops up. Why is this happening?</p>
  
  <p>Below are the layouts I use.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
      &lt;include
          android:id="@+id/toolbar_main"
          layout="@layout/toolbar_main"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" /&gt;
      &lt;android.support.design.widget.CoordinatorLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/coordinator_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_marginTop="?android:attr/actionBarSize"&gt;
          &lt;android.support.design.widget.AppBarLayout
              android:id="@+id/appbarLayout"
              android:layout_width="match_parent"
              android:layout_height="24dp"
              android:theme="@style/Theme.Design.Light"
              android:visibility="gone"&gt;
          &lt;/android.support.design.widget.AppBarLayout&gt;
          &lt;android.support.v7.widget.RecyclerView
              android:id="@+id/recyclerView"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:layout_behavior="@string/appbar_scrolling_view_behavior"/&gt;
      &lt;/android.support.design.widget.CoordinatorLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I am inflating this at <code>onCreateOptionsMenu()</code> pretty standard <code>SearchView</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  &lt;item android:id="@+id/search"
      android:title="@string/app_name"
      android:icon="@drawable/ic_search_tint_control_normal_24"
      android:showAsAction="always"
      android:actionViewClass="android.widget.SearchView" /&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p>toolbar_main :</p>
  
  
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
          &lt;Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?android:attr/actionBarSize"
              android:elevation="4dp" /&gt;
      &lt;/android.support.design.widget.AppBarLayout&gt;
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>Update:</p>
  
  <p>For now I solved the problem by using this in <code>onPreExecute()</code>. I am not sure why and how, but I can still get focus on <code>SearchView</code> by touching on it even after this... strange...</p>
  
  <pre><code>    if (searchView != null) {
          searchView.clearFocus();
          searchView.setFocusable(false);
      }
  </code></pre>