[英]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 并将我的代码放入其中,并使用Intent
从MainActivity
调用它。
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.