8

I see this question sets focus on the SearchView EditText when I activate a search from the ActionBar. However the keyboard does not come up when it gains focus. Shouldn't it, as it is just a normal EditText? (Is it a normal EditText?) This behaviour is seen on Android SDK level 11. (Samsung Galax Tab 7.7 with stock Android.)

I have a workaround at the moment that hooks in on the onOptionsItemSelected(MenuItem item) method of my Activity, showing the keyboard.

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        boolean menuSelectionHandeled = super.onOptionsItemSelected(item);
        // menu_search is the id of the menu item in the ActionBar
        if (item.getItemId() == R.id.menu_search) {
               mInputManager.showSoftInput(null, InputMethodManager.SHOW_IMPLICIT);
        }
        return menuSelectionHandeled;
    }

Where mInputManager is an instance of InputMethodManager.

The ActionBar is built with ActionBarSherlock, and since the target device is Android 3.x could this be the cause of the symptoms? As per ActionBarSherlock's FAQ :

The action bar on Android 3.x (also known as Honeycomb) does not implement all of the features of the one in Android 4.x (Ice Cream Sandwich). In order to provide a full action bar API on all platforms as well as unify the styling across all versions of Android the custom implementation is used.

Community
  • 1
  • 1
Diederik
  • 5,536
  • 3
  • 44
  • 60
  • Don't know if this really matters but i had a problem when my xml file contained a `EditText` as in the example files from ActionBarSherlock (ie: i couldn't get my callbacks for textchange etc to work) but when i changed that to a `SearchView` instead and added the proper callbacks it just started working as intended. Perhaps give that a try? – lfxgroove Jun 15 '12 at 08:03
  • Also, check out http://stackoverflow.com/questions/11011091/how-can-i-focus-on-a-collapsible-action-view-edittext-item-in-the-action-bar-wh – lfxgroove Jun 15 '12 at 08:18
  • Thanks @Anton that question makes me think there isn't a way to show the keyboard automatically. He has the same workaround as me. In my XML I definitely use a SearchView. Thanks – Diederik Jun 16 '12 at 08:05
  • Check it: http://stackoverflow.com/a/39635722/2535875 – Md Imran Choudhury Sep 22 '16 at 10:06

1 Answers1

0

This should work :

SearchView searchView = new SearchView(getContext());
searchView.setInputType(InputType.TYPE_CLASS_TEXT);
searchView.setBackgroundColor(Color.WHITE);
lokoko
  • 5,785
  • 5
  • 35
  • 68