Android监听和屏蔽home键Android监听和屏蔽home键
监听home键
public void onUserLeaveHint(){
Toast.makeText(this, "监听HOME键", Toast.LENGTH_SHORT).show();
}
屏蔽home键
1. 在activity中加上这段代码就可以屏蔽home键(onKeyDown事件会捕捉到
home键)。
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.La...
Android监听和屏蔽home键
监听home键
public void onUserLeaveHint(){
Toast.makeText(this, "监听HOME键", Toast.LENGTH_SHORT).show();
}
屏蔽home键
1. 在activity中加上这段代码就可以屏蔽home键(onKeyDown事件会捕捉到
home键)。
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
} 2.因为android系统自己对与home键power键在PhoneWindowManager中做
了处理,不会返回到上层应用的。以下为系统源码:
\frameworks\policies\base\phone\com\android\internal\policy\impl\PhoneWindowManager.java 1089行
if (code == KeyEvent.KEYCODE_HOME) {
// If a system window has focus, then it doesn't make sense
// right now to interact with applications.
WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
if (attrs != null) {
final int type = attrs.type;
if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
|| type ==
WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
// the "app" is keyguard, so give it the key
return false;
}
final int typeCount =
WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
for (int i=0; i
本文档为【Android监听和屏蔽home键】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。