立即打开键盘

时间:2016-12-15 17:30:39

标签: android keyboard

有两种方法:showSystemKeyboardhideSystemKeyboard。我认为一切都是合乎逻辑的,一种方法显示键盘,另一种隐藏它。

showSystemKeyboard onStart()方法中的键盘显示方法调用:

@Override
    public void onStart () {
        super.onStart ();
        if (allAvailableTags.isEmpty () && selectedTags.isEmpty ()) {
            Utils.showSystemKeyboard (tagNameInputView);
        }
    }

方法本身showSystemKeyboard

public static void showSystemKeyboard (EditText view) {
        if (view! = null) {
            InputMethodManager inputManager = (InputMethodManager) context.getSystemService (Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput (view, InputMethodManager.SHOW_IMPLICIT);
        }
    }

挑战在于,当你在我的类TagDialog中调用对话框时,会立即打开onStart()键盘上的方法。立刻说SHOW_FORCED常数一次不合适。

我尝试这种方法:

tagNameInputView.requestFocus();
    tagNameInputView.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (allAvailableTags.isEmpty() && selectedTags.isEmpty()) {
                InputMethodManager keyboard = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                keyboard.showSoftInput(tagNameInputView, 0);
            }
        }
    },200);

    tagNameInputView.requestFocus();
    tagNameInputView.postDelayed(new Runnable() {
        @Override
        public void run() {
            InputMethodManager keyboard = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            keyboard.hideSoftInputFromWindow(tagNameInputView.getWindowToken(), 0);
        }
    },200);

但是我仍然需要在打开键盘之前点击EditText字段(

0 个答案:

没有答案