-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: fix dialog button colors in dark mode (#15091)
* Core(Android): fix dialog button colors in dark mode Fix alert dialog button colors in dark mode. Use ?attr/colorOnSurface for text color in dialogs. This ensures contrasting color for both dark and light modes. * Core(Android): use AppCompat alert dialog in picker Use AppCompat version of AlertDialog in picker. This ensures consistent styling between picker dialog and alert dialog. * Controls.DeviceTests: add AlertDialogTests Add tests for checking brightness of AlertDialog button text. Co-authored-by: webwarrior <reg@webwarrior.ws> --------- Co-authored-by: Parham Saremi <parhaamsaremi@gmail.com>
- Loading branch information
1 parent
2ac61e5
commit cda3eb3
Showing
4 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/Controls/tests/DeviceTests/Elements/AlertDialog/AlertDialogTests.Android.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.DeviceTests.Stubs; | ||
using Microsoft.Maui.Platform; | ||
using Xunit; | ||
using AndroidX.AppCompat.App; | ||
using Android.Graphics; | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
public partial class AlertDialogTests: ControlsHandlerTestBase | ||
{ | ||
|
||
async Task<Color> GetDialogButtonTextColor(int nightMode) | ||
{ | ||
var mauiContextStub1 = new ContextStub(ApplicationServices); | ||
var activity = mauiContextStub1.GetActivity(); | ||
mauiContextStub1.Context = new Android.Views.ContextThemeWrapper(activity, Resource.Style.Maui_MainTheme_NoActionBar); | ||
Color color = Color.Transparent; | ||
await InvokeOnMainThreadAsync(() => | ||
{ | ||
var initialNightMode = activity.Delegate.LocalNightMode; | ||
activity.Delegate.SetLocalNightMode(nightMode); | ||
var builder = new AlertDialog.Builder(activity); | ||
var alertDialog = builder.Create(); | ||
alertDialog.Show(); | ||
var button = alertDialog.GetButton((int)Android.Content.DialogButtonType.Negative); | ||
var textColor = button.CurrentTextColor; | ||
color = new Color(textColor); | ||
activity.Delegate.SetLocalNightMode(initialNightMode); | ||
alertDialog.Hide(); | ||
}); | ||
|
||
return color; | ||
} | ||
|
||
[Fact] | ||
public void AlertDialogButtonColorLightTheme() | ||
{ | ||
var textColor = GetDialogButtonTextColor(AppCompatDelegate.ModeNightNo).Result; | ||
Assert.True(textColor.GetBrightness() < 0.5); | ||
} | ||
|
||
[Fact] | ||
public void AlertDialogButtonColorDarkTheme() | ||
{ | ||
var textColor = GetDialogButtonTextColor(AppCompatDelegate.ModeNightYes).Result; | ||
Assert.True(textColor.GetBrightness() > 0.5); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters