是否可以在不单击任何按钮的情况下弹出消息?
Is it possible to make a pop up message without clicking on any button?
AlertDialog.Builder myAlert = new AlertDialog.Builder(this);
myAlert.setMessage(username)
.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setTitle("Welcome To iShop!")
.create();
myAlert.show();
是否可以让它在 activity 启动时弹出?
只需将您编写的代码放入 Activity 的 onCreate() 方法中。
@Override
protected void onCreate(Bundle savedInstanceState) {
AlertDialog.Builder myAlert = new AlertDialog.Builder(this);
myAlert.setMessage(username)
.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setTitle("Welcome To iShop!")
.create();
myAlert.show();
}
AlertDialog.Builder myAlert = new AlertDialog.Builder(this);
myAlert.setMessage(username)
.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setTitle("Welcome To iShop!")
.create();
myAlert.show();
是否可以让它在 activity 启动时弹出?
只需将您编写的代码放入 Activity 的 onCreate() 方法中。
@Override
protected void onCreate(Bundle savedInstanceState) {
AlertDialog.Builder myAlert = new AlertDialog.Builder(this);
myAlert.setMessage(username)
.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setTitle("Welcome To iShop!")
.create();
myAlert.show();
}