问题描述
Xamarin android Toast View Rerun Null。
这是代码片段
Toast t = Toast.MakeText(context,message,shorOrLong);
Color c = color;
ColorMatrixColorFilter CM = new ColorMatrixColorFilter(new float[]
{
0,c.R,c.G,c.B,1,0
});
t.View.Background.SetColorFilter(CM);
t.Show();
这里 t.View 为空。
为此,我收到了空引用异常。非常感谢任何形式的帮助。
解决方法
为什么不这样
t.getView().getBackground().setColorFilter(CM);
t.show();
,
Snice Android 11,不推荐使用自定义 Toast。
我们无法在 toast 上设置背景颜色,如果您想自定义背景,请改用 Snackbar。
参考