1. 程式人生 > >android 中顯示和隱藏鍵盤

android 中顯示和隱藏鍵盤

/**
 * 隱藏軟體盤方法的其中一種
 *
 * @param token
 */
protected void hideSoftInput(IBinder token)
{
    if (token != null)
    {
        InputMethodManager im = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        im.hideSoftInputFromWindow(token,
                InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
/**
 * EditText獲取焦點並顯示軟鍵盤
 */
public static void showSoftInputFromWindow( ClearEditText editText) { editText.requestFocus(); InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.toggleSoftInput(0,InputMethodManager.SHOW_FORCED); }