Android隐藏输入法

时间:2024-10-30 17:37:02

输入法隐藏两种方式:

/**
* 隐藏输入法
*
* @param myActivity
*/
public static void hideInput(Activity myActivity,EditText et)
{
  if(et==null)
  {
    ((InputMethodManager) myActivity.getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(myActivity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
  }
  else
  {
    InputMethodManager inputMethodManager = (InputMethodManager) myActivity.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(et.getWindowToken(), 0); 
  }
}