Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Android toast with background colour and rounded corners

pinsterpinster Member ✭✭
edited December 2019 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();

Posts

  • DimChrisDimChris USMember ✭✭✭✭

    try this:

    var toast = Toast.MakeText(inventoryPreviewMain,"your text", ToastLength.Short);
    toast.View.Background.SetColorFilter(Color.DarkBlue, PorterDuff.Mode.SrcIn);
    toast.Show();
    
Sign In or Register to comment.