maui icon indicating copy to clipboard operation
maui copied to clipboard

The prompts displayed by DisplayAlert do not follow the theme set

Open emorell96 opened this issue 3 years ago • 4 comments

Description

The prompts displayed by DisplayAlert do not adhere to the theme set by using Application.Current.UserAppTheme.

image

Steps to Reproduce

  1. Set the theme to dark using Application.Current.UserAppTheme = AppTheme.Dark;
  2. Send a DisplayAlert on the main page on Android. The theme will not be respected and it will use the default light theme.

Version with bug

Release Candidate 1 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

API 30, Android 11

Did you find any workaround?

No response

Relevant log output

No response

emorell96 avatar Apr 14 '22 08:04 emorell96

@emorell96 Thank you so much for your bug report! Unfortunately, we cannot reproduce your issue with the information above, could you provide a sample project/screenshots or more details that we can reproduce your issue? That should greatly speed up the process, thanks!

kristinx0211 avatar Apr 18 '22 05:04 kristinx0211

Hi @emorell96. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Apr 18 '22 05:04 ghost

This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

ghost avatar Apr 25 '22 15:04 ghost

Hi, I'm not sure I understand why #7601 was closed as a duplicate of this issue... it is a completely separate issue that I am experiencing as well. On an Android device set to dark mode, DisplayAlert is presented with a dark gray background and dark (purple?) text that is barely readable. Has a workaround been identified for that issue? Thanks

mtanml avatar Oct 13 '22 21:10 mtanml

THIS IS A BIG PROBLEM.

LaraSQP avatar Dec 09 '22 23:12 LaraSQP

Application.Current.UserAppTheme only applys for the theme defined with AppThemeBinding as mentioned in this post. That means DisplayAlert, Picker, etc. don't inherit the specified theme. To fix this problem, make sure to run this code when switching themes:

#if ANDROID
            AndroidX.AppCompat.App.AppCompatDelegate.DefaultNightMode = Current.UserAppTheme switch
            {
                AppTheme.Light => AndroidX.AppCompat.App.AppCompatDelegate.ModeNightNo,
                AppTheme.Dark => AndroidX.AppCompat.App.AppCompatDelegate.ModeNightYes,
                _ => AndroidX.AppCompat.App.AppCompatDelegate.ModeNightFollowSystem
            };
#elif IOS
            Platform.GetCurrentUIViewController().OverrideUserInterfaceStyle = Current.UserAppTheme switch
            {
                AppTheme.Light => UIKit.UIUserInterfaceStyle.Light,
                AppTheme.Dark => UIKit.UIUserInterfaceStyle.Dark,
                _ => UIKit.UIUserInterfaceStyle.Unspecified
            };
#endif

I haven't tested on iOS but it should work.

jerry08 avatar Jan 04 '23 13:01 jerry08

Much appreciated. You rock, sir.

LaraSQP avatar Jan 04 '23 20:01 LaraSQP

So is there any solution for this? Since the one above is for xamarin forms?

SurkusGH avatar Jan 21 '23 10:01 SurkusGH

Okay, so just go:

$"[YourProject]"/Platforms/Android/Resources/values/colors. Change it there. That is it.

SurkusGH avatar Jan 21 '23 11:01 SurkusGH

The solution I mentioned is for both xamarin and MAUI. It works fine for me. From my knowledge, changing the values in Platforms/Android/Resources/values/colors.xml only changes the default button color in the dialog and in a few other areas. It doesn't change the dialog color.

I created a plugin that handles some workarounds (maui). If you want, you can check it out here.

jerry08 avatar Jan 21 '23 14:01 jerry08