title: How can I focus on a collapsible action view EditText item in the action bar (when it is expanded) and force the soft keyboard to open?
body: <p>I am using Jake Wharton's excellent <a href="http://actionbarsherlock.com">ActionBarSherlock</a> library and have a collapsible search action view. I want to popup the soft keyboard when the search action view is expanded.</p>
  
  <p>We can read a recommended way of doing this in a DialogFragment in the "<a href="http://android-developers.blogspot.nl/2012/05/using-dialogfragments.html">Using DialogFragments</a>" blog post by Google (altered a bit for readability).</p>
  
  <pre><code>// Show soft keyboard automatically
  mEditText.requestFocus();
  int mode = WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
  getDialog().getWindow().setSoftInputMode(mode);
  </code></pre>
  
  <p>This does not seem to work when expanding and requesting focus on a <a href="http://developer.android.com/guide/topics/ui/actionbar.html#ActionViewCollapsing">collapsable EditText action view</a>. I currently have this.</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getSupportMenuInflater();
      inflater.inflate(R.menu.my_activity, menu);
  
      MenuItem menuItem = menu.findItem(R.id.menu_search);
      final EditText searchText = (EditText) menuItem.getActionView();
  
      menuItem.setOnActionExpandListener(new OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
              return true; // Return true to collapse action view
          }
  
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
              searchText.requestFocus();
              int mode = WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
              getWindow().setSoftInputMode(mode);
              return true; // Return true to expand action view
          }
      });
  }
  </code></pre>
  
  <p>Here's my menu item definition in the my_activity menu xml file:</p>
  
  <pre><code>&lt;item
      android:id="@+id/menu_search"
      android:icon="@drawable/ic_menu_search"
      android:actionLayout="@layout/collapsible_edittext"
      android:showAsAction="always|collapseActionView"
      android:title="@string/menu_search"/&gt;
  </code></pre>
  
  <p>... and the collapsible_edittext action layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;EditText xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:hint="@string/hint_search"
      android:imeOptions="actionSearch"
      android:inputType="text"
      android:focusable="true"
      android:focusableInTouchMode="true" /&gt;
  </code></pre>
  
  <p>Caveat: I do not want to <em>force</em> the soft keyboard. When the user has a hardware keyboard requesting focus is sufficient.</p>
  
  <p>Any thoughts anyone?</p>