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();
活动开始时可以弹出它吗?
答案 0 :(得分:3)
只需将您编写的代码放在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();
}