覆盖的背部和家按钮的功能背部、按钮、功能

2023-09-08 08:45:02 作者:可否回来

我可以覆盖返回家居按钮(硬件)在 Android的功能?我的意思是像点击主页按钮应该去家里我的应用程序的屏幕而不是家手机屏幕

Can i override the functionality of back and homebuttons(hardware) in android? i mean like clicking on home button should go tohome screen of my app instead of home screen of mobile

推荐答案

主页按钮:

=>您不能覆盖​​的home键的行为。

=> You can't override the behaviour of home button.

返回按钮:

=>为了捕获或覆盖默认后退按钮preSS在安卓以下的onkeydown方法可以通过活动来实现。

=> In order to capture or override the default back button press in Android the following onKeyDown method can be implemented by the Activity.

 @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            moveTaskToBack(true);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

在案件的Andr​​oid 2.0+一个说服的方法是作为

In case of Android 2.0+ a convince method is provided as

  @Override
    public void onBackPressed() {

        // implement your override logic here
       return;
    }