Xamarin.Forms How to: Display Android’s Toast & SnackBar in PCL project
1 min readJul 9, 2016
Below is some code to help you to display Toast & SnackBar pop up ONLY in your Xamarin.Forms Android project and calling the pop-up in PCL code.
Prerequisite
- Convert Android project to use AppCompact & Material Design
- Install “Plugin.CurrentActivity” to Android project
- Basic understanding of DependencyService
We first need to declare a DependencyService interface so we could call this from our PCL project.
Next step would be implement the interface in Android project
Last step would be calling the code in PCL project. We limit the execution to run on Android only by querying the platform in runtime.
End Result
Full source code can be found here
Note: If you’re using shared project, I supposed you could just directly call the notification in the code using the compiler directive
#if __ANDROID__
..
#endif