zoukankan      html  css  js  c++  java
  • Android Dialog的四种情况 (转)

    四种dialog总结,下面的代码返回的是一个Dialog,在onClick里面用showDialog(anyDialog)调用就可以。

    一、一个确认一个取消

     private Dialog buildDialog1(Context context) {
      AlertDialog.Builder builder = new  AlertDialog.Builder(context);
      builder.setIcon(R.drawable.alert_dialog_icon);
      builder.setTitle(R.string.alert_dialog_two_buttons_title);
      builder.setPositiveButton(R.string.alert_dialog_ok,
        new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
          setTitle("点击了对话框上的确定按钮");
         }
        });
      builder.setNegativeButton(R.string.alert_dialog_cancel,
        new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
          setTitle("点击了对话框上的取消按钮");
         }
        });
      return builder.create();
     }

    二、带有大量文本

    private Dialog buildDialog2(Context context) {
      AlertDialog.Builder builder = new AlertDialog.Builder(context);
      builder.setIcon(R.drawable.alert_dialog_icon);
      builder.setTitle(R.string.alert_dialog_two_buttons_msg);
      builder.setMessage(R.string.alert_dialog_two_buttons2_msg);
      builder.setPositiveButton(R.string.alert_dialog_ok,
        new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
          setTitle("点击了对话框上的确定按钮");
         }
        });

      builder.setNeutralButton(R.string.alert_dialog_something,
        new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {

          setTitle("点击了对话框上的进入详细按钮");
         }
        });
      builder.setNegativeButton(R.string.alert_dialog_cancel,
        new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
          setTitle("点击了对话框上的取消按钮");
         }
        });
      return builder.create();
     }

    三、带输入框的,稍微复杂一点,要加人带textview、editview的layout

    private Dialog buildDialog3(Context context) {
      LayoutInflater inflater = LayoutInflater.from(this);
      final View textEntryView = inflater.inflate(
        R.layout.alert_dialog_text_entry, null);
      AlertDialog.Builder builder = new AlertDialog.Builder(context);
      builder.setIcon(R.drawable.alert_dialog_icon);
      builder.setTitle(R.string.alert_dialog_text_entry);
      builder.setView(textEntryView);
      builder.setPositiveButton(R.string.alert_dialog_ok,
        new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
          setTitle("点击了对话框上的确定按钮");
         }
        });
      builder.setNegativeButton(R.string.alert_dialog_cancel,
        new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
          setTitle("点击了对话框上的取消按钮");
         }
        });
      return builder.create();
     }

    四、带进度条的

     private Dialog buildDialog4(Context context) {
      ProgressDialog dialog = new ProgressDialog(context);
      dialog.setTitle("正在下载歌曲");
      dialog.setMessage("请稍候……");
      return dialog;
     }

  • 相关阅读:
    软件测试理论基础
    使用Pycharm官方统计代码行插件统计代码总行数
    Jmeter的配置文件解析
    python异常整理
    python2与python3的区别
    tomcat的server.xml配置
    异常:Error response from daemon: conflict: unable to delete 6fa48e047721 (cannot be forced)
    前端 -- 定位和z-index
    前端 -- background
    前端 -- 超链接导航栏案例
  • 原文地址:https://www.cnblogs.com/zhwl/p/2150985.html
Copyright © 2011-2022 走看看