Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue19676.cs
Original file line number Diff line number Diff line change
@@ -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,
}
}
};
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/Core/src/Platform/Android/SwitchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Loading