Chandu Ranwala
Chandu Ranwala

Reputation: 305

How to Customise default Alert in xamarin forms

I am trying to change the colour of Alert Buttons.

my alert like below.

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

I need to make Yes button Red both Android and iOS.

I need to get default alert view for both platform rather than creating a custom pop up.

is there any way to write a renderer for this?

Upvotes: 0

Views: 1117

Answers (2)

Muhammad Abu Mandor
Muhammad Abu Mandor

Reputation: 295

Hello man hope to get nice day

in iOS you need to use MessageCenter wherever you need to display Dailog and subscribe it in ApprDelegate as following:

        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);

in Android you just change colorAccent in you style file in resource hope to be useful.

Upvotes: 1

Adlorem
Adlorem

Reputation: 1507

If you need exact visual effect on both platforms you must write custom renderer, because DisplayAlert is not rendered by XF.

Upvotes: 0

Related Questions