0

Xamarin android Toast View Rerun Null.

Here is the code snippet

Toast t = Toast.MakeText(context, message, shorOrLong);
            Color c = color;
            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();

here t.View is null.

enter image description here

for that I am getting null reference exception. Any kind of help highly appreciated.

rykamol
  • 1,097
  • 1
  • 10
  • 19

2 Answers2

0

Why not so

 t.getView().getBackground().setColorFilter(CM);
    t.show();
0

Snice Android 11, custom toast is deprecated .

We can't set the background color on the toast , if you want to customize the background , use Snackbar instead .

Refer to

Toast.getView() returns null on Android 11 (API 30)

Method setView is deprecated

ColeX
  • 14,062
  • 5
  • 43
  • 240