How can I change default toast message color and background color in android?

后端 未结 15 769
执念已碎
执念已碎 2020-12-23 17:12

I want to create a toast message with background color is white and message color is black. My toast message is:

Toast.makeText(Logpage.this, \"Please Give          


        
15条回答
  •  生来不讨喜
    2020-12-23 17:54

    I was able to do it by setting the background color filter color and finding the toast resource ID and setting the text color.

    Android.Graphics.Color

        ///  Creates and displays a toast with the given text. 
        public void Show(string message)
        {
            // Create the toast.
            Toast toast = Toast.MakeText(Android.App.Application.Context, message, ToastLength.Long);
    
            // Set the background color.
            Android.Graphics.Color c = new Android.Graphics.Color(122, 193, 66, 255);
            Android.Graphics.ColorMatrixColorFilter CMF = new Android.Graphics.ColorMatrixColorFilter(new float[]
                {
                    0,0,0,0,(float)c.R,
                    0,0,0,0,(float)c.G,
                    0,0,0,0,(float)c.B,
                    0,0,0,1,0
                });
            toast.View.Background.SetColorFilter(CMF);
    
            // Set the text color.
            toast.View.FindViewById(Android.Resource.Id.Message).SetTextColor(new Android.Graphics.Color(0, 55, 103, 255));
    
            // Display the toast.
            toast.Show();
        }
    

提交回复
热议问题