How can I change the background color of a Toast in a Xamarin Forms Application?
I've tried this code on Android 11:
Context context = Android.App.Application.Context;
string message = "Hello toast!";
ToastLength duration = ToastLength.Short;
Toast t = Toast.MakeText(context, message, duration);
System.Drawing.Color c = Xamarin.Forms.Color.Green;
ColorMatrixColorFilter CM = new ColorMatrixColorFilter(new float[]
{
0,0,0,0,c.R,
0,0,0,0,c.G,
0,0,0,0,c.B,
0,0,0,1,0
});
t.View.Background.SetColorFilter(CM);
t.Show();
But I get the following error:
System.NullReferenceException: 'Object reference not set to an instance of an object.'