protected void ShowToast(string message, ToastLength length = ToastLength.Long)
        {
            var activity = Activity;

            if (activity == null)
            {
                return;
            }

            AToast.MakeText(activity, message, length).Show();
        }
    /// <summary>
    ///     Presents an toast based on the provided configuration.
    /// </summary>
    /// <param name="config">The dialog configuration.</param>
    protected override void PresentToast(IToastConfig config)
    {
        if (MessagingServiceCore.ActivityLifecycleCallbacks.CurrentActivity is AppCompatActivity appCompatActivity)
        {
            appCompatActivity.SafeRunOnUIThread(() =>
            {
                var toast = Android_Toast.MakeText(MessagingServiceCore.ActivityLifecycleCallbacks.CurrentActivity, config.Message, config.Duration);

                // If a layout resource ID has been provided, create the view with the view manager.
                if (config.LayoutResID.HasValue)
                {
                    // Inflate the custom Toast view and configure any subviews.
                    toast.View = MessagingServiceCore.ViewManager.InflateView(config.LayoutResID.Value, null, false, (view, dialogElement, autoHide) =>
                    {
                        switch (view, dialogElement)
                        {
        void IToastPlatformService.Show(string text, int duration)
        {
            try
            {
                if (MainThread.IsMainThread)
                {
                    Show_();
                }
                else
                {
                    MainThread.BeginInvokeOnMainThread(Show_);
                }

                void Show_()
                {
                    var context   = Application.Context;
                    var duration2 = (ToastLength)duration;

                    // https://blog.csdn.net/android157/article/details/80267737
                    try
                    {
                        if (toast == null)
                        {
                            toast = AndroidToast.MakeText(context, text, duration2);
                            if (toast == null)
                            {
                                throw new NullReferenceException("toast markeText Fail");
                            }
                        }
                        else
                        {
                            toast.Duration = duration2;
                        }
                        SetTextAndShow(toast, text);
                    }
                    catch (Exception e)
                    {
                        Log.Error(TAG, $"text: {text}{Environment.NewLine}{e}");
                        // 解决在子线程中调用Toast的异常情况处理
                        Looper.Prepare();
                        var _toast = AndroidToast.MakeText(context, text, duration2)
                                     ?? throw new NullReferenceException("toast markeText Fail(2)");
                        SetTextAndShow(_toast, text);
                        Looper.Loop();
                    }
Beispiel #4
0
 public void ShowToast(string message) =>
 Device.InvokeOnMainThreadAsync(() =>
                                AToast.MakeText(Application.Context, message, ToastLength.Short).Show());
Beispiel #5
0
 public void Show()
 {
     AndroidToast.MakeText(MainActivity, this.Text, ToastLength.Short).Show();
 }
 private void ToastMessage(string mssg)
 => Toast.MakeText(Activity, mssg, ToastLength.Long).Show();
Beispiel #7
0
 protected void ShowToast(string message, ToastLength length = ToastLength.Long)
 {
     AToast.MakeText(this, message, length).Show();
 }