2016-10-26 123 views
0

我有一个editText和两个按钮,当我点击取消,我有禁用编辑文本和隐藏键盘。键盘没有被解雇,即使我试图解雇Android

 case R.id.verify_cancel: 

hideMobileNoEditOption(); 
      showAndHideError(verify_layout, false); 
      showAndHideError(mobile_error_tv, false); 
      mobile_number_et.clearFocus(); 

这是hideMobileNoEditOption()的代码;

mobile_number_et.clearFocus(); 
     AppUtil.hideSoftKeyboard(this); 
     mobile_number_et.setCursorVisible(false); 
     mobile_number_et.setFocusable(false); 
     mobile_number_et.setEnabled(false); 
     mobile_number_et.setTextIsSelectable(false); 
     mobile_number_et.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.zero_title)); 

这是隐藏键盘的代码。

InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); 

     if (null != activity.getCurrentFocus()) { 

      inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); 

     } 

但是我的关键董事会没有因为上帝知道的原因而被解雇,任何人都可以请帮忙吗?在此先感谢

+0

也许你应该问神,因为他知道 –

+0

请大家帮忙找到解决方案。 –

+0

你确定你的'hideSoftInputFromWindow'方法被执行了吗?如果在隐藏软键盘之前清除焦点'(null!= activity.getCurrentFocus())''条件返回false并且不会隐藏键盘。 –

回答

1

试试这个,这个代码是为我工作

 /** 
    * For Hiding the keyboard 
    */ 

    public void hideKeyboard() { 
     View view = this.getCurrentFocus(); 
     if (view != null) { 
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
      imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
     } 
    } 
+0

这就像键盘正在隐藏并在一秒钟内回来。 –

+0

您使用请求焦点还是焦点更改侦听器?因为它会打开键盘 –

+0

雅,当我清除焦点时,编辑文本再次获得焦点。 –