- 论坛徽章:
- 0
|
EditText中关闭或者隐藏输入法
1、EditText有焦点(focusable为true)阻止输入法弹出
Java代码- 1.editText=(EditText)findViewById(R.id.txtBody);
- 2.
- 3. editText.setOnTouchListener(new OnTouchListener() {
- 4.
- 5. public boolean onTouch(View v, MotionEvent event) {
- 6.
- 7. editText.setInputType(InputType.TYPE_NULL); // 关闭软键盘
- 8.
- 9. return false;
- 10.
- 11. }
- 12.
- 13. });
-
复制代码 2、当EidtText无焦点(focusable=false)时阻止输入法弹出
Java代码- 1.InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
- 2.
- 3. imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
复制代码 3、显示输入法
Java代码- 1.InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- 2.imm.showSoftInput(m_receiverView(接受软键盘输入的视图(View)),InputMethodManager.SHOW_FORCED(提供当前操作的标记,SHOW_FORCED表示强制显示));
复制代码 4、隐藏输入法
Java代码- 1.((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是当前的Activity)
复制代码 5、获取输入法状态
Java代码- 1.InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
- 2.boolean isOpen=imm.isActive();
- 3.isOpen若返回true,则表示输入法打开
复制代码 |
|