当前位置: 代码迷 >> 综合 >> 弹出与关闭然键盘
  详细解决方案

弹出与关闭然键盘

热度:59   发布时间:2023-10-15 10:49:18.0

public class KeyboardUtils {

//传进来的view要是EditText

public static void openSoftInput(View view, Context context) {
((InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(
view, InputMethodManager.RESULT_SHOWN);
}


public static void closeSoftInput(View view, Context context) {
((InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

}


调用:

public void OpenKeyboard(View view) {
KeyboardUtils.openSoftInput(eText, this);
}


public void CloseKeyboard(View view) {
KeyboardUtils.closeSoftInput(eText, this);
}

  相关解决方案