对话框合集

2019-07-17  本文已影响0人  Margaret_lhp

对话框的几种常见方式:

* 创建一般对话框

AlertDialog alertDialog = new Builder(this).setTitle("提示") .setMessage("您确定退出该应用吗?").setPositiveButton("确定",null)

  setNegativeButton("取消",null).create();

alertDialog.show();

* 创建单选多选对话框

final String[] fruits = new String[] {"苹果", "西瓜", "哈密瓜", "梨" };

new Builder(this).setTitle("请输入您喜欢的水果").setSingleChoiceItems(fruits, 0,null).show();

final String[] fruits = new String[] {"苹果", "西瓜", "哈密瓜", "梨" };

final boolean[] fruitsCheck = new boolean[] { true, false, true, false };

new Builder(this).setTitle("请输入您喜欢的水果") .setMultiChoiceItems(fruits,fruitsCheck,null).setPositiveButton("确定", null).show();

* 创建带进度的对话框

final ProgressDialog dialog=new ProgressDialog(this);

dialog.setTitle("提示");

dialog.setMessage("正在拼命加载,请耐心等待...");

dialog.show();

new Timer().schedule(new TimerTask() {

      @Override

      publicvoid run() {

          dialog.dismiss();

      }

}, 3000);

上一篇 下一篇

猜你喜欢

热点阅读