EditText中关闭或者隐藏输入法

1、EditText有焦点(focusable为true)阻止输入法弹出 

Java代码 

editText=EditText)findViewByIdR.id.txtBody);  
  
        editText.setOnTouchListenernew OnTouchListener) {               
  
            public boolean onTouchView v, MotionEvent event) {    
  
                editText.setInputTypeInputType.TYPE_NULL); // 关闭软键盘        
  
                return false;  
  
            }  
  
        });    

2、当EidtText无焦点(focusable=false)时阻止输入法弹出  

Java代码 

InputMethodManager imm = InputMethodManager)getSystemServiceINPUT_METHOD_SERVICE);       
  
       imm.hideSoftInputFromWindoweditText.getWindowToken), 0);      

3、显示输入法 

Java代码 

InputMethodManager imm = InputMethodManager) getSystemServiceContext.INPUT_METHOD_SERVICE);       
imm.showSoftInputm_receiverView接受软键盘输入的视图View)),InputMethodManager.SHOW_FORCED提供当前操作的标记,SHOW_FORCED表示强制显示));    

4、隐藏输入法 

Java代码 

InputMethodManager)getSystemServiceINPUT_METHOD_SERVICE)).hideSoftInputFromWindowWidgetSearchActivity.this.getCurrentFocus).getWindowToken), InputMethodManager.HIDE_NOT_ALWAYS);  WidgetSearchActivity是当前的Activity)    

5、获取输入法状态 

Java代码 

InputMethodManager imm = InputMethodManager)getSystemServiceContext.INPUT_METHOD_SERVICE);  
boolean isOpen=imm.isActive);  
isOpen若返回true,则表示输入法打开  

Published by

风君子

独自遨游何稽首 揭天掀地慰生平