Android听取backbutton&菜单按钮一起长按

时间:2017-07-13 06:12:12

标签: android ontouchlistener onlongclicklistener

我正在压倒backbutton& amp;的行为。菜单按钮单击&长按一下。如何在Android代码中检测到这一点

屏幕截图取自Nexus手机版(6.0)

点击后退&菜单按钮在一起,我得到了这个日志

 Cancelling event due to no window focus: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x68, repeatCount=0, eventTime=69741827, downTime=69741172, deviceId=-1, source=0x101 } I 

enter image description here

1 个答案:

答案 0 :(得分:0)

这是覆盖Back Button的示例代码!

@Override
public void onBackPressed() {

    //This Override Method Alters System Back Button's default function

    Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
    startActivity(intent);
}