首页 > 解决方案 > 如何在 xamarin 表单中自定义默认警报

问题描述

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

我的警报如下。

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

我需要同时制作和制作Yes按钮。RedAndroidiOS

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

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

标签: c#xamarin.forms

解决方案


你好男人希望得到美好的一天

在 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 希望有用。


推荐阅读