new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.heart)
.setTitle("警告")
.setMessage("确定删除吗?")
.setPositiveButton("确定",null)
.setNegativeButton("不确定",null)
.setNeutralButton("取消",null)
.setCancelable(false)
.show();

final EditText edt = new EditText(MainActivity.this);
new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.heart)
.setTitle("请输入")
.setView(edt)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this,"输入:" + edt.getText().toString(),Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("取消",null)
.show();

final String [] items = {"选项一","选项二","选项三","选项④"};
new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.heart)
.setTitle("列表")
.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this,"点击了:" + items[i],Toast.LENGTH_SHORT).show();
}
})
.setPositiveButton("确定", null)
.setNegativeButton("取消",null)
.show();

final int pos = 2;
new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.heart)
.setTitle("单选")
.setSingleChoiceItems(items,pos,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this,"点击了:" + items[i],Toast.LENGTH_SHORT).show();
}
})
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this,"选中:" + items[pos],Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("取消",null)
.show();

final boolean checkedItems [] = {false,true,true,false};
new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.heart)
.setTitle("多选")
.setMultiChoiceItems(items, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i, boolean b) {
Toast.makeText(MainActivity.this,(b ? "选中:" : "未选中:") + items[i],Toast.LENGTH_SHORT).show();
}
})
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String s = "选中:";
for(int j = 0;j < items.length;++j){
if(checkedItems[j]){
s = s + items[j] + "、";
}
}
Toast.makeText(MainActivity.this,s,Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("取消",null)
.show();

final View login = View.inflate(MainActivity.this,R.layout.login,null);
final AlertDialog dlg = new AlertDialog.Builder(MainActivity.this).setIcon(R.drawable.heart)
.setTitle("登录")
.setView(login)
.create();
login.findViewById(R.id.btn_login).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"用户名:" + ((EditText)login.findViewById(R.id.edtName)).getText().toString() + " 密码:" + ((EditText)login.findViewById(R.id.edtPwd)).getText().toString(),Toast.LENGTH_LONG).show();
dlg.dismiss();
}
});
dlg.show();
