Forum Xamarin Xamarin.Forms

DisplayAlert button color

MikeBealeMikeBeale Member ✭✭

Where does DisplayAlert get the color used for the buttons?

Simply using DisplayAlert:
await DisplayAlert("Alert!", "This is DisplayAlert", "OK");

Is it possible to change this color on "OK"? It's also used in Picker and on Switch too.



  • dinesh314850dinesh314850 Member ✭✭

    Dear @MikeBeale
    You can get Latest Design Popup and Alert :

  • ColeXColeX Member, Xamarin Team Xamurai

    Different from Picker, Switch , DisplayAlert is not a rendered control in XF, we can't use custom renderer to customize it .

    You could write DependencyService for custom Dialogs and use some custom layouts.

    Refer the solution :

  • MikeBealeMikeBeale Member ✭✭

    Thanks for your replies.

    @dinesh314850 That Popup plugin will come in useful for another project I have to do at a later date.

    @ColeX That looked a bit too much to simply change a color, it wasn't really important so thought I would leave it.

    But today I was looking into adding a SplashScreen and going through the Xamarin docs, one step was to add to the Resources/values/styles.xml file.
    In there I spotted an item called colorAccent
    Changing this does what I need, it changes the OK/Cancel buttons on DisplayAlert, the color on a Switch control, and also the color for the Entry field the cursor is in.

  • petr_bruzekpetr_bruzek Member ✭✭

    in Xamarin.Forms projet and iOS part it can be simply set in Main.cs by Appearance:

    UIView.AppearanceWhenContainedIn(typeof(UIAlertView)).TintColor = UIColor.Red;
    UIView.AppearanceWhenContainedIn(typeof(UIAlertController)).TintColor = UIColor.Red;

  • petr_bruzekpetr_bruzek Member ✭✭
    edited July 16

    In Android part of Xamarin.Forms it can be set by styles - in Resources/values/styles.xml set colorAccent

        <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
            <item name="colorAccent">#53d3ff</item>
Sign In or Register to comment.