How to focus and show soft keyboard when a EditText is shown in action bar?

后端 未结 2 428
礼貌的吻别
礼貌的吻别 2021-01-18 19:26

I used ActionBarSherlock to create ActionBar it has a search button that shows an AutoCompleteEditText (SHOW_AS_COLLAPSIBLE_ACTION_VIEW) When Searc

2条回答
  •  遥遥无期
    2021-01-18 20:19

    Found the Solution:

    searchWidgetItem.setOnActionExpandListener(new OnActionExpandListener() {
    
                @Override
                public boolean onMenuItemActionExpand(MenuItem item) {
                    searchBar.post(new Runnable() {
                        @Override
                        public void run() {
                            searchBar.requestFocus();
                            imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.showSoftInput(searchBar,
                                    InputMethodManager.SHOW_IMPLICIT);
                        }
                    });
                    return true;
                }
    
                @Override
                public boolean onMenuItemActionCollapse(MenuItem item) {
    
                    return true;
                }
    });
    

提交回复
热议问题