Toasts
Sometimes we have to provide a small notification to the user to tell them that something has happened. At the same time, we don't want to interrupt the user's task in any way. That's where toast notifications come in. We can use toast notifications to display subtle notifications in our app.
How to do it...
We can create toast notifications with the Toast
type as follows:
A simple text toast is created through the
MakeText()
method, as shown here:using (var toast = Toast.MakeText( this, "This is a toast...", ToastLength.Short)) { toast.Show(); }
There are a few aspects we can customize using the various setter methods:
using (var toast = Toast.MakeText( this, "This is another toast...", ToastLength.Short)) { toast.SetGravity(GravityFlags.Center, 0, 0); toast.SetMargin(24, 24); toast.Show(); }
We can also specify an entire view to use instead of the default text view through the
View
property:using (var toast = new Toast(ApplicationContext)) using (var image = new ImageView(this...