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;
- }
- });
2、当EidtText无焦点(focusable=false)时阻止输入法弹出
- InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
3、显示输入法
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(m_receiverView(接受软键盘输入的视图(View)),InputMethodManager.SHOW_FORCED(提供当前操作的标记,SHOW_FORCED表示强制显示));
4、隐藏输入法
- ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是当前的Activity)
5、获取输入法状态
- InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
- boolean isOpen=imm.isActive();
- isOpen若返回true,则表示输入法打开