简体   繁体   English

如何在弹出 AlertDialog 时隐藏 MainActivity?

[英]How Can i hide the MainActivity while pop up AlertDialog?

I want to hide MainActivity when AlertDialog is shown.我想在显示AlertDialog时隐藏MainActivity I create new Activity and put my code in it and call it from MainActivity by using Intent .我创建新的 Activity 并将我的代码放入其中,并使用IntentMainActivity调用它。

My Code of AlertDialog :我的AlertDialog代码:

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class Dialog extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AlertDialog.Builder builder1 = new AlertDialog.Builder(Dialog.this);
        builder1.setTitle("RONQ");
        builder1.setMessage(MainActivity.mesgList.get(MainActivity.currentMsgNumber));
        builder1.setPositiveButton("ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        builder1.show();

    }
}

And Intent code is: Intent代码是:

Intent intent = new Intent();
                    intent.setClass(MainActivity.this, Dialog.class);
                    startActivity(intent);

You don't need Intent :你不需要Intent

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("message")
            .setPositiveButton(getString(R.string.update), (dialogInterface, i) -> {
                                    //do something
                                }).setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
//do something 
    }).setCancelable(false).create().show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在MainActivity(class)的AlertDialog(class)框中接收值而不将控制权传递给AlertDialog类(Android Development) - how can i receive value from AlertDialog(class) box in MainActivity(class) without passing control to AlertDialog class(Android Development) 如何从BroadcastReceiver隐藏和显示MainActivity上的视图 - How can I hide and show views on a MainActivity from a BroadcastReceiver 如何在MainActivity(或应用程序)的开头隐藏片段? - How can I hide a fragment on start of my MainActivity( or the application)? 我如何从 MainActivity 的弹出登录转到另一个活动 - how do i go from pop up login of MainActivity to another activity 单击按钮弹出AlertDialog - AlertDialog to pop up on button click 设备屏幕关闭时如何显示Alertdialog或窗口弹出? - How to show Alertdialog or windows pop up when device screen off? Alertdialog在while语句中弹出 - Alertdialog pop inside a while statement 每次返回 MainActivity 时 AlertDialog 都会重新启动 - AlertDialog restarted each time I return to MainActivity 如何隐藏我的应用程序的弹出窗口? - How to hide the pop up for my application? 如何从警报对话框更改主要活动中的可见性编辑文本 - how to change visibility edittext in mainactivity from alertdialog
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM