/// <summary>
    /// Shows the alert dialog.
    /// </summary>
    /// <param name="title">Title.</param>
    /// <param name="Message">Message.</param>
    /// <param name="positiveButtonText">Positive button text.</param>
    /// <param name="negativeButtonText">Negative button text.</param>
    /// <param name="PositiveEvent">Positive event.</param>
    /// <param name="NegativeEvent">Negative event.</param>
    public static void ShowAlertDialog(string title = "提示!", string Message = "是否退出?", string positiveButtonText = "是", string negativeButtonText = "否", Action PositiveEvent = null, Action NegativeEvent = null)
    {
        alertDialog = new AndroidJavaObject("android.app.AlertDialog$Builder", unityActivity);
        var PositiveClick = new DialogOnClickListener();

        PositiveClick.onClickDelegate = (d, w) =>
        {
            if (PositiveEvent != null)
            {
                PositiveEvent();
            }
        };
        var NegativeClick = new DialogOnClickListener();

        NegativeClick.onClickDelegate = (d, w) =>
        {
            if (NegativeEvent != null)
            {
                NegativeEvent();
            }
        };
        alertDialog = alertDialog.Call <AndroidJavaObject>("setTitle", title);
        alertDialog = alertDialog.Call <AndroidJavaObject>("setMessage", Message);
        alertDialog = alertDialog.Call <AndroidJavaObject>("setPositiveButton", positiveButtonText, PositiveClick);
        alertDialog = alertDialog.Call <AndroidJavaObject>("setNegativeButton", negativeButtonText, NegativeClick);
        alertDialog = alertDialog.Call <AndroidJavaObject>("create");

        alertDialog.Call("show");
    }
    // Use this for initialization
    void Start()
    {
        if (button != null)
        {
            button.onClick.AddListener(delegate {
                DialogOnClickListener confirmListener = new DialogOnClickListener();
                confirmListener.onClickDelegate       = onConfirm;

                DialogOnClickListener cancelListener = new DialogOnClickListener();
                cancelListener.onClickDelegate       = onCancel;

                AlertDialog alertDialog = new AlertDialog(AndroidTools.UnityActivity);
                alertDialog.setTitle("标题震惊");
                alertDialog.setMessage("确定要干那事儿?");
                alertDialog.setPositiveButton("当然", confirmListener);
                alertDialog.setNegativeButton("算了", cancelListener);//如果不需要取消后的事件处理,把cancelListener换成new DialogOnClickListener ()就行,上面也不用声明cancelListener
                alertDialog.create();
                alertDialog.show();
            });
        }
    }
示例#3
0
 public void setNegativeButton(string name, DialogOnClickListener cancelListener)
 {
     builder             = builder.Call <AndroidJavaObject>("setNegativeButton", name.toJavaString(), cancelListener);
     isNegativeButtonSet = true;
 }
示例#4
0
 public void setPositiveButton(string name, DialogOnClickListener confirmListener)
 {
     builder             = builder.Call <AndroidJavaObject>("setPositiveButton", name.toJavaString(), confirmListener);
     isPositiveButtonSet = true;
 }