Toasts Plugin For Xamarin And Windows

Update: This article is for version 2.0.4 and below of the Toasts plugin. If you wish to use 3.0.0+, please look at Toast Notifications for Xamarin Forms.

As a recent contributor to the Toasts Plugin For Xamarin and Windows I thought it would be good to write about what it does and how you can use it in your project now that there we have finally released version 2.0.0. The major update was support for WinRT and by default UWP along with a few minor bug fixes and a breaking namespace change to align with other Xamarin Plugins.

Toasts

For those that might have come from the iOS side, Toasts are what Windows and Android call Local Notifications. A small message that pops up on the screen to let the user know that some event has occurred. You then have the option to click on the toast to perform an action if it is configured.

android   ios   windows

Setup

  1. Install the Toasts Plugin for Xamarin and Windows in your native project and PCL if applicable.
  2. Add in the appropriate initialization code in each native project.

Note: You don’t have to use Xamarin Forms inbuilt dependency injection, you can use any one that might better suit your project.

Android

In the MainActivity.cs

Android

Windows

In the MainPage.xaml.cs

Windows

iOS

In the AppDelegate.cs

iOS

Usage

To show a toast anywhere in your application, takes just one easy line of code. (after you get the reference to the Toast Notifier)

Customization

One of the great things about the plugin is it lets you override the rendering of the toasts to however you want. You will need to create a new ToastLayoutRenderer for each platform you wish to customize. The easiest way to see how it all works is to look at the default toast layout renderers in the plugin source code

When you create your own, just pass it in the Init() method in each native platform as appropriate.

Roadmap

This is more of a what I intend to do but offer no guarantees when or if it will be completed

  • Use Snackbar for Android instead of Croutons
  • Allow toasts to launch an action upon click
  • Toasts at the bottom of the screen

 

 

 


XAMARIN.FORMS MONTHLY NEWSLETTER

JOIN 1,000+ SUBSCRIBERS

  1. Don't miss out on updates
  2. The latest info from this site, Xamarin and the community
  3. Unsubscribe at any time*

* We use MailChimp, with double opt-in, and instant unsubscribe

Microsoft MVP | Xamarin MVP | Xamarin Certified Developer | Exrin MVVM Framework | Xamarin Forms Developer | Melbourne, Australia

Related Posts

10 Comments

  1. Shahriat Hossain

    How can I use this for my xamarin PCL project? I have code below of my app.cs file:

    MessagingCenter.Subscribe(this, “ShowAlert”, (s, msg) =>
    {
    // run on UI thread
    Device.BeginInvokeOnMainThread(() =>
    {
    // want to use here the toast });
    });

  2. Alex

    Hi Adam,

    How could I custom the toast notification (Image, Background color, Text color and Toast opacity)?

    I am using version 2.0.4

    Great work!

  3. Olamide James

    Hello, Please I got the error below

    Severity Code Description Project File Line Suppression State
    Error Could not install package ‘Toasts.Forms.Plugin 3.1.2’. You are trying to install this package into a project that targets ‘.NETPortable,Version=v4.5,Profile=Profile259’, but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. 0

    Kindly assist

    1. Adam Pedley

      3.1.2 can only be installed on a PCL Profile 111 or .NET Standard 1.1 and above. This is because the toasts plugin does not support WIndows Phone Silverlight. As such, it can not install on a Profile 259.

  4. Olamide James

    Hello,
    Thanks for the reply. I was able to use it in Xamarin Android but I could not reproduce the same effect as above. This is my implementation:

    var notificator = DependencyService.Get();

    var options = new NotificationOptions()
    {
    Title = “GVE”,
    Description = “Registration Successful”

    };
    var result = await notificator.Notify(options);

    I think the dll has changed because i couldn’t use the sample you gave above, no types for Info,Success or failed.

    Am I missing anything.
    Thanks in advance.

  5. David Gerding

    Super helpful. This may be a weird request, but is it possible to add “Toast without notification” to the roadmap. I was looking for a quick cross platform way to do short lived pop ups that disappear but I’m hoping to able to call some of those without persisting a notification event in the app tray since that’s a little heavy handed for some of the ux.

    Thanks!
    Dave Gerding

  6. Mounika Kola

    Hi Adam Pedley,

    Thanks for the plugin, I’m trying to use this plugin in my project unfortunately its not showing images in toast (success,info etc images)

Leave A Comment?