Android 打开和关闭软键盘
16lz
2021-01-23
public class SoftInputUtils {/** * 隐藏软键盘 * @param acitivity */public static void closedSoftInput(Activity acitivity){if(null!=acitivity && acitivity.getCurrentFocus()!=null){ if(null!=acitivity.getWindow()){ acitivity.getWindow().getDecorView().clearFocus(); InputMethodManager im = ((InputMethodManager) acitivity.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE)); if(null!=im){ im.hideSoftInputFromWindow(acitivity.getWindow().getDecorView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } }}/** * 打开软键盘 * @param acitivity */public static void openSoftInput(final Activity acitivity){ Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { InputMethodManager imm = (InputMethodManager)acitivity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } }, 300);}}
更多相关文章
- android 键盘不弹出
- android中隐藏以及显示软键盘代码
- android朋友圈监听键盘状态 点击空白区域隐藏键盘
- Android监听键盘上的确定键等
- Solution of issue: Android soft keyboard overlap with input
- android详细解释键盘和鼠标事件
- Android虚拟键盘弹出时挡住EditText解决方法
- Android各种键盘挡住输入框解决办法