title: How to Implement Floating SearchWidget Android
body: <p>I am trying to implement the search widget in the current android apps, but just can't get it done <img src="https://i.stack.imgur.com/sTgSN.jpg" alt="Google I/O app"> and I've not been able to implement it. Below is my code</p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
      SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
      SearchView searchView = (SearchView) menu.findItem(R.id.search_bar).getActionView();
      searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
      searchView.setIconifiedByDefault(false);
      return true;
  }
  
  @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_settings) {
          return true;
      } else if (id == R.id.search_bar) {
          //startActivity(new Intent(this, SearchResultActivity.class));
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p><strong>MenuItem</strong></p>
  
  <pre><code> &lt;item android:id="@+id/search_bar"
      android:title="Search"
      android:orderInCategory="100"
      android:icon="@android:drawable/ic_menu_search"
      app:showAsAction="always|collapseActionView"
      app:actionViewClass="android.support.v7.widget.SearchView"/&gt;
  </code></pre>
  
  <p><strong>SearchActivity</strong></p>
  
  <pre><code> public class SearchResultActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.search_custom_text);
      handleIntent(getIntent());
  }
  
  @Override
  protected void onNewIntent(Intent intent) {
      super.onNewIntent(intent);
      handleIntent(intent);
  }
  
  private void handleIntent(Intent intent) {
  
      if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
          String query = intent.getStringExtra(SearchManager.QUERY);
      }
  }
  }
  </code></pre>
  
  <p><strong>Manifest</strong></p>
  
  <pre><code>&lt;activity android:name=".MainActivity"
          android:enabled="true"&gt;
  
          &lt;!--&lt;meta-data android:name="android.app.searchable"
              android:resource="@xml/searchable"/&gt;--&gt;
  
          &lt;meta-data android:name="android.app.default_searchable"
              android:value=".SearchResultActivity"/&gt;
  
      &lt;/activity&gt;
  
      &lt;activity android:name=".SearchResultActivity"
          android:enabled="true"
          android:launchMode="singleTop"
          android:parentActivityName=".MainActivity"&gt;
  
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.SEARCH"/&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/intent-filter&gt;
  
          &lt;!--&lt;meta-data android:name="android.app.default_searchable"
              android:value=".SearchResultActivity" /&gt;--&gt;
  
          &lt;meta-data android:name="android.app.searchable"
              android:resource="@xml/searchable"/&gt;
  
      &lt;/activity&gt;
  </code></pre>
  
  <p>This is what I'm thinking, but I've not yet tried it. I did implemented a floating activity in my project. From the look of what's below, I think it's a floating Activity right.
  Any help would be appreciated.</p>