maui icon indicating copy to clipboard operation
maui copied to clipboard

Android: AlertDialog Button can't customize button color

Open Jean-RochSDX opened this issue 7 months ago • 1 comments

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: image

Result on .NET8: image

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

Jean-RochSDX avatar Jan 23 '24 14:01 Jean-RochSDX

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.

ghost avatar Jan 26 '24 16:01 ghost

Verified this on VS 17.10.0 Preview 1.0(8.0.6). Repro on Android 14.0-API34 with below Project: BugAlertDIalogButtonColor.zip

XamlTest avatar Mar 07 '24 06:03 XamlTest

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.

kubaflo avatar Mar 14 '24 01:03 kubaflo

Styles Maui.MainTheme.NoActionBar impacting current splash screen in Android platform .NET 8 MAUI.

mounikakola avatar May 22 '24 11:05 mounikakola