Is there a way to style a toast in xamarin forms? like changing the corner radius or background color? at least for android. I am using dependency service to show the toasts an it works fine but I prefer to style the toast a bit. Thanks in advance.
Andorid toast:
[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, message, ToastLength.Short).Show();
}
}
}
Ios Toast:
[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, message, UIAlertControllerStyle.Alert);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null);
}
void dismissMessage()
{
if (alert != null)
{
alert.DismissViewController(true, null);
}
if (alertDelay != null)
{
alertDelay.Dispose();
}
}
}
}