微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xamarin 表单样式吐司

如何解决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 举报,一经查实,本站将立刻删除。