无法在搜索查看自动显示键盘

问题描述:

该搜索查看的重点是在默认情况下,但是当我试图表现出软键盘 - 它不会发生:

The SearchView is focused by default, but when I try to show software keyboard - it doesn't happen:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

但是,当我点击搜索查看 - 它的作用。为什么呢?

But when I click on the SearchView - it does. Why?

修正了!

mSearchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
                        @Override
                        public void onFocusChange(View view, boolean hasFocus) {
                            if (hasFocus) {
                                showInputMethod(view.findFocus());
                            }
                        }
                    });

private void showInputMethod(View view) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
          imm.showSoftInput(view, 0);
        }
    }