Xamarin 表单样式吐司

问题描述

有没有办法以 xamarin 形式设置吐司样式?比如改变圆角半径或背景颜色?至少对于安卓来说。 我正在使用依赖服务来显示吐司,它工作正常,但我更喜欢稍微设计一下吐司的样式。提前致谢。

安卓吐司:

[assembly: Xamarin.Forms.Dependency(typeof(MessageAndroid))]
namespace DeliveryApplication.Droid.DependencyService
{
    class MessageAndroid : IMessage
    {
        public void LongToast(string message)
        {
            Toast.MakeText(Application.Context,message,ToastLength.Long).Show();
        }

        public void ShortToast(string message)
        {
            Toast.MakeText(Application.Context,ToastLength.Short).Show();
        }
    }
}

IOS 吐司:

[assembly: Xamarin.Forms.Dependency(typeof(MessageIOS))] 
namespace DeliveryApplication.Droid.DependencyService
{

    class MessageIOS : IMessage
    {
        const double LONG_DELAY = 3.5;
        const double SHORT_DELAY = 2.0;

        NSTimer alertDelay;
        UIAlertController alert;
        public void LongToast(string message)
        {
            ShowAlert(message,LONG_DELAY);
        }

        public void ShortToast(string message)
        {
            ShowAlert(message,SHORT_DELAY);
        }

        private void ShowAlert(string message,double seconds)
        {
            alertDelay = NSTimer.CreateScheduledTimer(seconds,(obj) =>
            {
                dismissMessage();
            });
            alert = UIAlertController.Create(null,UIAlertControllerStyle.Alert);
            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert,true,null);
        }

        void dismissMessage()
        {
            if (alert != null)
            {
                alert.dismissViewController(true,null);
            }
            if (alertDelay != null)
            {
                alertDelay.dispose();
            }
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)