在展开的 SearchView 上返回上一个 activity 的操作栏后退按钮
Action bar back button returning to previous activity on expanded SearchView
我有一个 SearchView,它会在启动 activity 时自动展开搜索,但我希望它左侧的后退按钮 return 到上一个 activity而不是关闭它。关于如何实现这一点有什么想法吗?
谢谢。
试试这个
public void onBackPressed() {
showExitAlertBox();
}
public void showExitAlertBox() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setMessage("You want to quit the play?");
//Yes Quit then go to category page
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int button) {
Intent intent = new Intent(getApplicationContext(), PREVIOUSACTIVITY.class);
startActivity(intent);
finish();
}
});
//no Quit stay on same page
alertDialog.setNegativeButton("NO", null);
alertDialog.show();
}
我有一个 SearchView,它会在启动 activity 时自动展开搜索,但我希望它左侧的后退按钮 return 到上一个 activity而不是关闭它。关于如何实现这一点有什么想法吗?
谢谢。
试试这个
public void onBackPressed() {
showExitAlertBox();
}
public void showExitAlertBox() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setMessage("You want to quit the play?");
//Yes Quit then go to category page
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int button) {
Intent intent = new Intent(getApplicationContext(), PREVIOUSACTIVITY.class);
startActivity(intent);
finish();
}
});
//no Quit stay on same page
alertDialog.setNegativeButton("NO", null);
alertDialog.show();
}