本文介绍了如何捕捉到主页按钮单击安卓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是在我发现,Home键计算器的答案可以被覆盖?但我发现在Android市场被称为Mxplayer在那里你可以锁定所有按键,而播放视频的应用程序。他们是如何做的呢?我们可以在Android的覆盖home键?
From the answers in the stackoverflow I found that Home button can be overriden?But I found an application in the android market called "Mxplayer" where you can lock all buttons while playing video. How are they doing this?Can we override the home button in android?
推荐答案
此方法适用于高达2.3,
This solution works upto 2.3,
覆盖下面的方法,在你的活动,
Override the below method in your Activity,
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}
和现在处理这种关键事件,
And now handle the key event like this,
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_HOME)
{
Log.i("Home Button","Clicked");
}
if(keyCode==KeyEvent.KEYCODE_BACK)
{
finish();
}
return false;
};
这篇关于如何捕捉到主页按钮单击安卓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!