您的位置:首页 > 移动开发 > Android开发

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

2015-06-01 16:18 218 查看
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,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: