Skip to content Skip to sidebar Skip to footer

How To Focus And Show Soft Keyboard When A Edittext Is Shown In Action Bar?

I used ActionBarSherlock to create ActionBar it has a search button that shows an AutoCompleteEditText (SHOW_AS_COLLAPSIBLE_ACTION_VIEW) When Search button is clicked, EditText is

Solution 1:

Found the Answer :

searchWidgetItem.setOnActionExpandListener(newOnActionExpandListener() {

            @OverridepublicbooleanonMenuItemActionExpand(MenuItem item) {
                searchBar.post(newRunnable() {
                    @Overridepublicvoidrun() {
                        searchBar.requestFocus();
                        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(searchBar,
                                InputMethodManager.SHOW_IMPLICIT);
                    }
                });
                returntrue;
            }

            @OverridepublicbooleanonMenuItemActionCollapse(MenuItem item) {

                returntrue;
            }
});

Solution 2:

If you still have the problem, so call the following method

imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

instead of

imm.showSoftInput(searchBar, InputMethodManager.SHOW_IMPLICIT);

Post a Comment for "How To Focus And Show Soft Keyboard When A Edittext Is Shown In Action Bar?"