Android弹出和收起输入法键盘

自动弹起键盘

    diaryEdit = findViewById(R.id.content_edit);
        diaryEdit.postDelayed(new Runnable() {
     
            @Override
            public void run() {
     
                //获得焦点
                diaryEdit.requestFocus();
                InputMethodManager manager = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
                if (manager != null) manager.showSoftInput(diaryEdit, 0);
            }
        }, 100);

收起键盘

InputMethodManager manager = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
                if (manager != null) {
     
                    manager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                }

你可能感兴趣的:(Android学习笔记,android,输入法键盘)