【问题标题】:Action bar back button returning to previous activity on expanded SearchView操作栏后退按钮返回到展开的 SearchView 上的上一个活动
【发布时间】:2017-03-19 01:53:27
【问题描述】:

我有一个 SearchView,它在启动活动时会自动展开以进行搜索,但我希望它左侧的后退按钮返回到上一个活动,而不是关闭它。关于如何实现这一点的任何想法?

谢谢。

【问题讨论】:

    标签: android android-layout android-studio android-fragments searchview


    【解决方案1】:

    试试这个

    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();
    
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多