【发布时间】:2017-03-19 01:53:27
【问题描述】:
我有一个 SearchView,它在启动活动时会自动展开以进行搜索,但我希望它左侧的后退按钮返回到上一个活动,而不是关闭它。关于如何实现这一点的任何想法?
谢谢。
【问题讨论】:
标签: android android-layout android-studio android-fragments searchview
我有一个 SearchView,它在启动活动时会自动展开以进行搜索,但我希望它左侧的后退按钮返回到上一个活动,而不是关闭它。关于如何实现这一点的任何想法?
谢谢。
【问题讨论】:
标签: android android-layout android-studio android-fragments searchview
试试这个
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();
}
【讨论】: