How To Display Toast Messages In Xamarin Forms?

How To Display Toast Messages In Xamarin Forms?

Mobile app development
Toasts Message

What is Xamarin?

Xamarin is a tool supported by Microsoft. It provides way to developers to build native mobile applications. Those applications have native features and share common code at the same time.

Why do we need of Xamarin?

As it is developed by Microsoft for creating mobile application, so if you want to be run your same application on various platforms like IOS, Android and windows then you can achieve this by using Xamarin application.

What is the use of Toasts?

Toasts displays message that disappears after sometimes to the users.so messages do not stuck on the screen in mobile applications that is best use of toast.

How to use Toasts in Xamarin application?

First of all, add one interface in main project named as “IToastMessage”.Declare one function named as DisplayMessage(string Message) and pass string parameter to that method.

Capture-toast3

How to use Toasts in Xamarin android application?

First of all, add one class named as “Message_Driod.cs” in android application project and implement “IToastMessage” interface as below:

CaptureToast1

For “IToastMessage” interface give reference of your main project where you have created your interface to your android application project by right click on Reference folder of your android application project, then select add reference and click on project tab then select your main project and press ok.

How to use Toasts in Xamarin IOS application?

First of all, add one class named as “Message_IOS.cs” in android application project and implement “IToastMessage” interface as below:

 alt=

For “IToastMessage” interface give reference of your main project where you have created your interface to your android application project by right click on Reference folder of your android application project, then select add reference and click on project tab then select your main project and press ok.

How to display Toasts in Xamarin Application?

Now You can display toast by using below code in main project code files:DependencyService.Get<IToastMessage>().DisplayMessage(“Your message here.”);

Posted on August 24, 2018 by Keyur Patel
Keyur Patel
Tags: