安卓教程之Dialog

ProgressDialog

ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setTitle("通知窗口");
progressDialog.setMessage("读取中");
progressDialog.setCancelable(true);
#dialog弹出后会点击屏幕或物理返回键,dialog消失
#dialog.setCanceledOnTouchOutside(false);
#dialog弹出后会点击屏幕,dialog不消失;点击物理返回键dialog消失
progressDialog.show();

AlertDialog

AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("警告窗口");
dialog.setMessage("重要事件");
dialog.setPositiveButton("OK",new DialogInterface.OnClickListener()
{
    @Override
    public void onClick(DialogInterface dialog,int which){}
});
dialog.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){
    @Override
    public void onClick(DialogInterface dialog, int which){
    }
});
dialog.show();

你可能感兴趣的:(安卓教程之Dialog)