diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SwitchThumbShouldBeVisibleWithShadow.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SwitchThumbShouldBeVisibleWithShadow.png new file mode 100644 index 000000000000..1ea0c5a9579d Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SwitchThumbShouldBeVisibleWithShadow.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue19676.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue19676.cs new file mode 100644 index 000000000000..4d4ecdb8f0e8 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue19676.cs @@ -0,0 +1,45 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 19676, "Android Switch Control Thumb Shadow missing when ThumbColor matches background", PlatformAffected.Android)] +public class Issue19676 : ContentPage +{ + public Issue19676() + { + BackgroundColor = Color.FromArgb("#F2F5F8"); + + Content = new VerticalStackLayout + { + Padding = 20, + Spacing = 20, + Children = + { + new Label + { + Text = "Switch with ThumbColor matching background", + FontSize = 16, + FontAttributes = FontAttributes.Bold, + }, + new Label + { + Text = "The switch thumb should be visible with a shadow, even though ThumbColor matches the background.", + FontSize = 14, + }, + new Switch + { + IsToggled = true, + ThumbColor = Color.FromArgb("#F2F5F8"), + OnColor = Colors.Red, + AutomationId = "TestSwitch", + Margin = new Thickness(10, 20, 15, 0), + VerticalOptions = LayoutOptions.Center + }, + new Label + { + Text = "Expected: Switch thumb is visible with shadow", + FontSize = 14, + TextColor = Colors.Gray, + } + } + }; + } +} diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/SwitchThumbShouldBeVisibleWithShadow.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/SwitchThumbShouldBeVisibleWithShadow.png new file mode 100644 index 000000000000..e2081f0edfdc Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/SwitchThumbShouldBeVisibleWithShadow.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19676.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19676.cs new file mode 100644 index 000000000000..aaf241520660 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19676.cs @@ -0,0 +1,20 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue19676 : _IssuesUITest +{ + public override string Issue => "Android Switch Control Thumb Shadow missing when ThumbColor matches background"; + + public Issue19676(TestDevice device) : base(device) { } + + [Test] + [Category(UITestCategories.Switch)] + public void SwitchThumbShouldBeVisibleWithShadow() + { + App.WaitForElement("TestSwitch"); + VerifyScreenshot(); + } +} diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/SwitchThumbShouldBeVisibleWithShadow.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/SwitchThumbShouldBeVisibleWithShadow.png new file mode 100644 index 000000000000..46fba05be8e2 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/SwitchThumbShouldBeVisibleWithShadow.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/SwitchThumbShouldBeVisibleWithShadow.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/SwitchThumbShouldBeVisibleWithShadow.png new file mode 100644 index 000000000000..64778b07ab31 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/SwitchThumbShouldBeVisibleWithShadow.png differ diff --git a/src/Core/src/Platform/Android/SwitchExtensions.cs b/src/Core/src/Platform/Android/SwitchExtensions.cs index e551b53aaac6..5cd7c9d63933 100644 --- a/src/Core/src/Platform/Android/SwitchExtensions.cs +++ b/src/Core/src/Platform/Android/SwitchExtensions.cs @@ -28,7 +28,13 @@ public static void UpdateThumbColor(this ASwitch aSwitch, ISwitch view) if (thumbColor is not null) { - aSwitch.ThumbDrawable?.SetColorFilter(thumbColor, FilterMode.SrcAtop); + // Use ThumbTintList instead of SetColorFilter to preserve the thumb shadow + // SetColorFilter flattens the drawable and removes the shadow effect + aSwitch.ThumbTintList = ColorStateListExtensions.CreateDefault(thumbColor.ToPlatform()); + } + else + { + aSwitch.ThumbTintList = null; } }