EditText中关闭或者隐藏输入法
1、EditText有焦点(focusable为true)阻止输入法弹出
editText=(EditText)findViewById(R.id.txtBody); editText.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { editText.setInputType(InputType.TYPE_NULL); // 关闭软键盘 return false; } });
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(m_receiverView(接受软键盘输入的视图(View)),InputMethodManager.SHOW_FORCED(提供当前操作的标记,SHOW_FORCED表示强制显示));
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是当前的Activity)
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);boolean isOpen=imm.isActive();isOpen若返回true,则表示输入法打开