Android开发中模拟Home键操作和关闭手机软键盘

来源:互联网 发布:桌面便签提醒软件 编辑:程序博客网 时间:2024/06/04 19:47

1,在点击返回时,不想退出应用,直接模拟HOME键操作,可以写在onKeyDown事件中,也可以写在其它自己想要实现的地方:

                Intent intent = new Intent(Intent.ACTION_MAIN);
// 创建一个新的任务栈(这个必须要写)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_HOME);
this.startActivity(intent);

2,监听关闭手机软键盘:

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null && this.getCurrentFocus() != null) {
inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}

3,

0 0
原创粉丝点击