Toast toast = Toast.MakeText(Application.Context,
message, ToastLength.Short);
toast.View.SetBackgroundColor(Android.Graphics.Color.ParseColor("#98A5AD"));
toast.SetGravity(GravityFlags.Center, 0, 0);
toast.Show();
这是我定制的吐司。它接受蓝色作为一种颜色。但是,这会覆盖角点半径。我该如何防止这种情况发生呢?
另外,我如何在吐司中使用自定义字体?
谢谢您:)
发布于 2021-03-24 07:03:56
您可以尝试以下代码:
Toast toast = Toast.MakeText(Application.Context, "this is test!", ToastLength.Long);
toast.View.Background.SetColorFilter(Android.Graphics.Color.ParseColor("#98A5AD"), PorterDuff.Mode.SrcIn);
toast.SetGravity(GravityFlags.Center, 0, 0);
toast.Show();
如果你想在吐司文本中使用自定义字体,请看一下:
Toast toast = Toast.MakeText(Application.Context, "this is test!", ToastLength.Long);
View view = toast.View;
toast.View.Background.SetColorFilter(Android.Graphics.Color.ParseColor("#98A5AD"), PorterDuff.Mode.SrcIn);
TextView text = (TextView)view.FindViewById(Android.Resource.Id.Message);
var typeface = Typeface.Create("customfont", Android.Graphics.TypefaceStyle.Bold);
text.Typeface= typeface;
toast.Show();
关于在Android中使用自定义字体,你可以看看:
https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/resources-in-android/fonts
https://stackoverflow.com/questions/66764277
复制