maui
maui copied to clipboard
Android: AlertDialog Button can't customize button color
Description
When displaying an alert dialog it is since .net 8 not possible anymore to change the button text color when changing the property colorPrimary in the file Platforms\Android\Resources\values\colors.xml
Expected result on .NET7:
Result on .NET8:
Steps to Reproduce
Run the .NET8 Application (PocAlert) project. Click on the button "Click me" => An alert appears with OK written in black.
Run the .NET8 Application (PocAlert7) project. Click on the button "Click me" => An alert appears with OK written in red as defined in colors.xml.
Link to public reproduction project repository
https://github.com/Jean-RochSDX/BugAlertDIalogButtonColor
Version with bug
8.0.3
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
7.0.101
Affected platforms
Android
Affected platform versions
Android 11
Did you find any workaround?
No
Relevant log output
No response
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
Verified this on VS 17.10.0 Preview 1.0(8.0.6). Repro on Android 14.0-API34 with below Project: BugAlertDIalogButtonColor.zip
Hi, @Jean-RochSDX I opened a PR that fixes it, but as @pjcollins suggested it is better to override the alert button's colors in styles like this:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MyAppTheme" parent="Maui.MainTheme.NoActionBar">
<item name="alertDialogTheme">@style/MyAlertDialogTheme</item>
</style>
<style name="MyAlertDialogTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="colorPrimary">@color/colorPrimary</item>
</style>
</resources>
Therefore, I've closed that PR.
Thanks to it we can by default adjust the button colors to the app theme so that they look good in both the light and dark mode.
Styles Maui.MainTheme.NoActionBar impacting current splash screen in Android platform .NET 8 MAUI.