如何禁用home键?
我已经完成了一个应用程序..在退出应用程序时,我使用警报对话框方法在退出时输入了密码。但是当出现警报对话框按钮时,按主页按钮时的移动应用程序将进入主屏幕..我想要那个按主页键时的移动应禁用。
我尝试此代码,当按主屏幕键时,它不会进入主屏幕。但是当它在警报对话框模式下打开,同时按主屏幕键时,它会进入主屏幕
@Override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
i have done a app..while exiting the app i made password to enter while exiting i using alert dialog method.But when the alert dialog button is appear that movement while press home button the app is coming to home screen.. i want that movement when press home key should disable.
I try this code its work when press home key press it won't go to home screen.But when it open in alert dialog mode while press on home key it going to home screen
@Override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Home键很特别。您无法禁用它,抱歉。
您应该相应地处理您的活动生命周期:在需要时保存并重新加载相关变量。不要依赖您的活动始终位于屏幕顶部!
Home key is special. you cannot disable it, sorry.
You should handle your activity lifecycle accordingly: save and reload relevant variables when needed. Do not rely on your activity always be on top screen!
要在打开警报对话框时禁用 Home 键,请使用以下代码:
To disable the Home key, while the alert dialog is opened, use this code: