我们可以覆盖硬件后退按钮功能。我有点困惑,请帮助我。
答案 0 :(得分:8)
您还可以覆盖onBackPressed()
:
@Override
public void onBackPressed(){
//Your action
}
答案 1 :(得分:6)
@Override public void onBackPressed(){
//do your stuff here
}
如果有任何与特定密钥相关的内容,那么你可以这样做:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.Any_Key_Code) {
//your stuff here
return true;
}
return super.onKeyDown(keyCode, event);
}
答案 2 :(得分:2)
看到这个
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Toast.makeText(getApplicationContext(), "back button pressed",
Toast.LENGTH_SHORT).show();
return true;
}
return super.onKeyDown(keyCode, event);
}
答案 3 :(得分:2)
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// do your stuff here
return true;
}
return super.onKeyDown(keyCode, event);
}
答案 4 :(得分:1)
@Override
public void onBackPressed() {
// Action to be performed
super.onBackPressed();
}