Dialog(弹窗)

Dialog一般用自定义的,系统自带的也有

//系统自带Dialog
AlertDialog.Builder b=new AlertDialog.Builder(Reign.this); b.setTitle("是否登录");//设置标题 b.setMessage("是否登录"); //设置内容 b.setPositiveButton("是", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent i = new Intent(); Bundle bundle=new Bundle(); i.setClass(Reign.this, Login.class); bundle.putSerializable("data", (Serializable) user); i.putExtras(bundle); startActivity(i); dialog.dismiss(); } }); b.setNegativeButton("否", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(Reign.this, "还是登录吧", Toast.LENGTH_SHORT).show(); dialog.dismiss();//销毁弹窗 } }); b.create().show();//先create,再show
    //
b.setCancelable(true);点击空白处,是否消失弹窗,默认是true,消失
 
   

//学了自定义在说

转载于:https://www.cnblogs.com/Xacm/p/5465940.html

你可能感兴趣的:(Dialog(弹窗))