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

大憨熊 提交于 2019-12-01 19:16:23

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;
            }
});
Ayman Mahgoub

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!