Hello,
Welcome to our Microsoft Q&A platform!
From android document Toast, we can see:
This method was deprecated in API level 30.
Custom toast views are deprecated. Apps can create a standard text toast with the makeText(android.content.Context, java.lang.CharSequence, int) method, or use a Snackbar when in the foreground. Starting from Android Build.VERSION_CODES#R, apps targeting API level Build.VERSION_CODES#R or higher that are in the background will not have custom toast views displayed.
So the solution with setting a custom view on Toast is deprecated for API 30 and forward.
You can use SnackBar
from Xamarin Community toolkit package, which uses native implementation in platforms where natively supported, because Toast is deprecated in API level 30, a SnackBar without an Action is equivalent to a Toast.
Started with the Xamarin Community Toolkit
- Install the Package on all your projects
- include the namespace using Xamarin.CommunityToolkit.Extensions;
- In your page code-behind show a SnackBar upon an event await this.DisplayToastAsync("This is a Toast Message");
await this.DisplayToastAsync("This is a Toast Message for 5 seconds", 5000);
You may specify a duration for the SnackBar to disappear (in milliseconds) or leave the default one which equals 3 seconds.
Note:
Resources
SnackBar Sample is here: https://github.com/xamarin/XamarinCommunityToolkit/blob/main/samples/XCT.Sample/Pages/Views/SnackBarPage.xaml.cs
Official Repo: https://github.com/xamarin/XamarinCommunityToolkit
Official Docs: https://learn.microsoft.com/en-us/xamarin/community-toolkit/
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.