c# - Xamarin 形成风格吐司
问题描述
有没有办法以 xamarin 形式为吐司设计样式?比如改变圆角半径或背景颜色?至少对于安卓来说。我正在使用依赖服务来展示 toast,它工作得很好,但我更喜欢对 toast 进行一些样式化。提前致谢。
安道尔吐司:
[assembly: Xamarin.Forms.Dependency(typeof(MessageAndroid))]
namespace DeliveryApplication.Droid.DependencyService
{
class MessageAndroid : IMessage
{
public void LongToast(string message)
{
Toast.MakeText(Application.Context, message, ToastLength.Long).Show();
}
public void ShortToast(string message)
{
Toast.MakeText(Application.Context, message, ToastLength.Short).Show();
}
}
}
IOS吐司:
[assembly: Xamarin.Forms.Dependency(typeof(MessageIOS))]
namespace DeliveryApplication.Droid.DependencyService
{
class MessageIOS : IMessage
{
const double LONG_DELAY = 3.5;
const double SHORT_DELAY = 2.0;
NSTimer alertDelay;
UIAlertController alert;
public void LongToast(string message)
{
ShowAlert(message, LONG_DELAY);
}
public void ShortToast(string message)
{
ShowAlert(message, SHORT_DELAY);
}
private void ShowAlert(string message, double seconds)
{
alertDelay = NSTimer.CreateScheduledTimer(seconds, (obj) =>
{
dismissMessage();
});
alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null);
}
void dismissMessage()
{
if (alert != null)
{
alert.DismissViewController(true, null);
}
if (alertDelay != null)
{
alertDelay.Dispose();
}
}
}
}
解决方案
推荐阅读
- apache-spark - 如何从数据框转换为 RDD 并使用案例类返回
- python - 提取列表中具有特定元素的行
- sql-server - 获取动态数据透视结果到临时表 SQL Server
- git - Git 存储库中的 Git 存储库,用于客户端使用分发文件
- java - 如何改进 Java 泛型通配符签名
- r - 如何在 dplyr 中按固定数量的行分组?
- python - 如何修复 portaudio 错误,PortAudio 未初始化?
- reactjs - 网络::ERR_CERT_COMMON_NAME_INVALID,Axios
- swift - 如何使用 UserDefault 添加两个值
- python - 一些子图的属性不能循环工作