When we want to let user know that something happening we can use Toast.
Let’s see how to create Toast in in Android in Xamarin Forms
Create xamrin foms application with Android project

- In .net standard project add a Interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IToastMessageService | |
| { | |
| void ShowToastMessage(string message); | |
| } |
- In Android project add ToastMessageService and implement the IToastMessageService
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [assembly: Xamarin.Forms.Dependency(typeof(ToastMessageService))] | |
| namespace ToastTestXamarin.Droid | |
| { | |
| public class ToastMessageService : IToastMessageService | |
| { | |
| public void ShowToastMessage(string message) | |
| { | |
| Toast.MakeText(Android.App.Application.Context, message, ToastLength.Long).Show(); | |
| } | |
| } | |
| } |
- In MainPage.xaml add a button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8" ?> | |
| <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | |
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
| xmlns:local="clr-namespace:ToastTestXamarin" | |
| x:Class="ToastTestXamarin.MainPage"> | |
| <Button x:Name="BtnToastMessage" Text="Show Toast" Clicked="ShowToast"></Button> | |
| </ContentPage> |
- And in the code behind implement the event handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void ShowToast(Object sender, EventArgs args) | |
| { | |
| DependencyService.Get<IToastMessageService>().ShowToastMessage("Test Toast Message"); | |
| } |
Finally run the project 🙂

Get the sample project on Github




























