Android toast with background colour and rounded corners

pinsterpinster Member ✭✭
edited December 3 in Xamarin.Android

Hi, I'm trying to create a simple toast popup in android with a custom background colour which i have created using the following code snippet.

Toast toast = Toast.MakeText(Application.Context, "error occured", ToastLength.Long); toast.View.SetBackgroundColor(Android.Graphics.Color.ParseColor("#ed4447")); toast.Show();

I am struggling to make the corners rounded and increase the size of the text to improve appearance. I've tried to create a GradientDrawable object and set the corner radius then set the background drawable of my toast. (it does suggest SetBackgroundDrawable is depricated). Has anyone got any ideas how to achieve this? I'm hoping this is something i can simply do from code. thank you.

Toast toast = Toast.MakeText(Application.Context, "error occured", ToastLength.Long); Android.Graphics.Drawables.GradientDrawable drawable = new Android.Graphics.Drawables.GradientDrawable(); drawable.SetCornerRadius(30); toast.View.SetBackgroundDrawable(drawable); toast.View.SetBackgroundColor(Android.Graphics.Color.ParseColor("#ed4447")); toast.View.SetPadding(10, 10, 10, 10); toast.Show();

Sign In or Register to comment.