Android对话框简单例子

Android对话框简单例子

通知对话框(Dialog Notification)

   AlertDialog.Builder builder = new AlertDialog.Builder(this);
   builder.setTitle("通知对话框");
   builder.setIcon(R.mipmap.ic_launcher);
   builder.setMessage("是否升级程序?");
   builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
       @Override
       public void onClick(DialogInterface dialogInterface, int i) {
           Log.i("Click","PositiveButton");
       }
   });
   builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
       @Override
       public void onClick(DialogInterface dialogInterface, int i) {
           Log.i("Click","NegativeButton");
       }
   });
  //builder.create();
   builder.show();

单选对话框(Dialog SingleChoice)

   AlertDialog.Builder builder = new AlertDialog.Builder(this);
   builder.setTitle("单选对话框");
   final String[] items = new String[]{"Mode_DZ","Mode_DD","Mode_DEMO"};
   builder.setSingleChoiceItems(items, 1, new DialogInterface.OnClickListener() {
       @Override
       public void onClick(DialogInterface dialogInterface, int i) {
           Log.i("Click2",items[i]+" 被点击了");
           dialogInterface.cancel();
       }
   });
   builder.show();

多选对话框(Dialog MultiChoice)

   AlertDialog.Builder builder = new AlertDialog.Builder(this);
   builder.setTitle("多选对话框");
   final String[] items = new String[]{"Mode_DZ","Mode_DD","Mode_DEMO"};
   boolean[] status = new boolean[]{true,true,false};
   builder.setMultiChoiceItems(items, status, new DialogInterface.OnMultiChoiceClickListener() {
       @Override
       public void onClick(DialogInterface dialogInterface, int i, boolean b) {
           Log.i("Click3",items[i]+"被点击了"+b);
       }
   });
   builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
       @Override
       public void onClick(DialogInterface dialogInterface, int i) {
       }
   });
   builder.show();

进度条对话框(ProgressDialog)

   final ProgressDialog dialog = new ProgressDialog(this);
   dialog.setTitle("提醒");
   dialog.setMessage("正在加载中...");
   dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
   dialog.setMax(100);
   dialog.show();
   new Thread(new Runnable() {
       @Override
       public void run() {
           for (int i = 0; i < 100; i++) {
               dialog.setProgress(i);
               try {
                   Thread.sleep(100);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           dialog.dismiss();
       }
   }).start();

按xml布局的对话框

   LayoutInflater factory = LayoutInflater.from(this);
   final View textEntryView = factory.inflate(R.layout.posrangedlg, null);
   etMinPos = (EditText) textEntryView.findViewById(R.id.et_MinPosition);
   etMaxPos = (EditText) textEntryView.findViewById(R.id.et_MaxPosition);

   AlertDialog dlg = new AlertDialog.Builder(this)
           .setTitle("输入位置范围")
           .setView(textEntryView)
           .setPositiveButton("OK", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int whichButton) {

                     String min = etMinPos.getText().toString();
                     String max = etMaxPos.getText().toString();
               }
           })
           .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int whichButton) {
               }
           })
           .create();
   dlg.show();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值