繁体   English   中英

如何在 xamarin 表单中自定义默认警报

[英]How to Customise default Alert in xamarin forms

我正在尝试更改警报按钮的颜色。

我的警报如下。

await DisplayAlert("Question?", "Would you like to play a game", "Yes", "No");

我需要在AndroidiOS都将Yes按钮设为Red

我需要为两个平台获取默认警报视图,而不是创建自定义弹出窗口。

有没有办法为此编写渲染器?

你好男人希望有美好的一天

在 iOS 中,您需要在任何需要显示 Dailog 的地方使用 MessageCenter 并在 ApprDelegate 中订阅它,如下所示:

        UIAlertController vc = UIAlertController.Create("", titleWeSendFromMessageCenterArgs, UIAlertControllerStyle.Alert);
        UIAlertAction action = UIAlertAction.Create("OK", UIAlertActionStyle.Default, null);
        vc.AddAction(action);

        vc.View.TintColor = UIColor.Red;//or whatever you want

        Window.RootViewController.PresentViewController(vc, true, null);

在 Android 中,您只需更改资源中样式文件中的 colorAccent 希望有用。

如果您在两个平台上都需要精确的视觉效果,则必须编写自定义渲染器,因为 DisplayAlert 不是由 XF 渲染的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM