Пример #1
0
        public static void ToastMessage(string message, Color color, string goPage)
        {
            Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
            {
                ToastConfig tc = new ToastConfig(message);
                tc.SetBackgroundColor(color);

                if (color == Color.Aquamarine)
                {
                    tc.SetMessageTextColor(Color.Black);
                    tc.SetPosition(ToastPosition.Bottom);
                }
                else
                {
                    tc.SetMessageTextColor(Color.White);
                    tc.SetPosition(ToastPosition.Bottom);
                }

               
                tc.SetDuration(TimeSpan.FromSeconds(5.0));


                tc.SetAction(x => x.SetText("Ir >").SetAction(() => App.gotopage(goPage)));
              

                UserDialogs.Instance.Toast(tc);
            });
        }
        /// <summary>
        ///    Can call directly.
        /// </summary>
        /// <param name="toastStr"></param>
        /// <param name="actionText"></param>
        /// <param name="backgroundColor"></param>
        /// <param name="messageTextColor"></param>
        /// <param name="actionTextColor"></param>
        /// <param name="useTimeout"></param>
        /// <param name="toastDissolveSeconds"></param>
        /// <param name="action"></param>
        public static void ShowToastInternal
        (
            string toastStr,
            string actionText        = "OK",
            Color?backgroundColor    = default,
            Color?messageTextColor   = default,
            Color?actionTextColor    = default,
            bool useTimeout          = true,
            int toastDissolveSeconds = TOAST_DISSOLVE_SECONDS,
            Action action            = null
        )
        {
            if (toastStr.IsEmpty())
            {
                return;
            }

            var newConfig =
                new ToastConfig(toastStr).SetMessageTextColor
                (
                    messageTextColor ?? Color.White
                );

            if (backgroundColor.HasValue)
            {
                newConfig.SetBackgroundColor(backgroundColor.Value);
            }

            newConfig.SetDuration(
                TimeSpan.FromSeconds(useTimeout && (toastDissolveSeconds > 0) ? toastDissolveSeconds : WAIT_FOREVER));

            var newAction = new ToastAction();

            // Must add "SetAction"
            if ((action != null) || actionText.IsNotEmpty())
            {
                if (action != null)
                {
                    newAction.SetAction(action);
                }

                if (actionText.IsNotEmpty())
                {
                    newAction.SetText(actionText);
                    newAction.SetTextColor(actionTextColor ?? Color.White);
                }

                newConfig.SetAction(newAction);
            }
            // ELSE skip "SetAction"

            UserDialogs.Instance.Toast(newConfig);
        }