title: Android Search Activity in Single Activity
body: <p>I am trying to make my app consist a SINGLE activity.  This activity should be able to create a search and also receive a search.  Unfortunately, I am getting a "double" search bar in my SearchView when I click on the search button in the action bar.  I mean that there is a search bar (dark-- SearchView) that appears for a second in the action bar, and then a second one (white) appears OVER the action bar.  Any help?  What am I doing wrong?
  Sorry, this search thing is all new and confusing to me.</p>
  
  <p>MainActivity (the only activity):</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  Menu mMenu;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      //getSupportActionBar().setDisplayShowTitleEnabled(false);
      setContentView(R.layout.activity_main);
  
      handleIntent(getIntent());
  }
  
  @Override
  protected void onNewIntent(Intent intent) {
      handleIntent(intent);
  }
  
  private void handleIntent(Intent intent) {
      if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
          String query = intent.getStringExtra(SearchManager.QUERY);
          //use the query to search your data somehow
      }
  }
  
  @SuppressLint("NewApi")
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      mMenu = menu;
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
  
  
  
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) {
          SearchManager searchManager =
                  (SearchManager) getSystemService(Context.SEARCH_SERVICE);
          SearchView searchView =
                  (SearchView) menu.findItem(R.id.search).getActionView();
          searchView.setSearchableInfo(
                  searchManager.getSearchableInfo(getComponentName()));
          searchView.setIconifiedByDefault(false);
      }
  
  
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case R.id.search:
              onSearchRequested();
              return true;
          default:
              return false;
      }
  }
  
  @SuppressLint("NewApi")
  @Override
  public boolean onSearchRequested() {
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
          MenuItem mi = mMenu.findItem(R.id.search);
          if(mi.isActionViewExpanded()){
              mi.collapseActionView();
          } else{
              mi.expandActionView();
          }
      } else{
          //onOptionsItemSelected(mMenu.findItem(R.id.search));
      }
      return super.onSearchRequested();
  }
  }
  </code></pre>
  
  <p>main.xml (the menu xml):</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:com.brianco.andypedia="http://schemas.android.com/apk/res-auto" &gt;
  
  &lt;item android:id="@+id/search"
        android:title="@string/action_settings"
        android:icon="@drawable/ic_launcher"
        android:actionProviderClass="android.support.v7.widget.ShareActionProvider"
        com.brianco.andypedia:showAsAction="always|collapseActionView"
        com.brianco.andypedia:actionViewClass="android.support.v7.widget.SearchView" /&gt;
  
  &lt;item
      android:id="@+id/action_settings"
      android:orderInCategory="100"
      android:showAsAction="never"
      android:title="@string/action_settings"/&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <p>searchable.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;searchable xmlns:android="http://schemas.android.com/apk/res/android"
      android:label="@string/app_name"
      android:hint="@string/search_hint"
      android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" /&gt;
  </code></pre>
  
  <p>in the manifest:</p>
  
  <pre><code>&lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/Theme.AppCompat.Light.DarkActionBar" &gt;
      &lt;activity
          android:name="com.brianco.andypedia.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.SEARCH" /&gt;
          &lt;/intent-filter&gt;
          &lt;meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /&gt;
      &lt;/activity&gt;
  
      &lt;meta-data android:name="android.app.default_searchable"
          android:value=".MainActivity" /&gt;
  </code></pre>