diff --git a/src/Controls/src/Core/Platform/Android/TabbedPageManager.cs b/src/Controls/src/Core/Platform/Android/TabbedPageManager.cs index 5d6b9b990f24..584b82e8ddaf 100644 --- a/src/Controls/src/Core/Platform/Android/TabbedPageManager.cs +++ b/src/Controls/src/Core/Platform/Android/TabbedPageManager.cs @@ -635,19 +635,11 @@ protected virtual ColorStateList GetItemTextColorStates() } else { - if (barItemColor is not null) - defaultColor = barItemColor.ToPlatform().ToArgb(); + // UnSelected tabs TextColor + defaultColor = GetItemTextColor(barItemColor, _originalTabTextColors); - if (barItemColor is null && _originalTabTextColors is not null) - defaultColor = _originalTabTextColors.DefaultColor; - - if (!defaultColor.HasValue) - return _originalTabTextColors; - else - checkedColor = defaultColor.Value; - - if (barSelectedItemColor is not null) - checkedColor = barSelectedItemColor.ToPlatform().ToArgb(); + // Selected tabs TextColor + checkedColor = GetItemTextColor(barSelectedItemColor, _originalTabTextColors); } _newTabTextColors = GetColorStateList(defaultColor.Value, checkedColor); @@ -655,6 +647,11 @@ protected virtual ColorStateList GetItemTextColorStates() return _newTabTextColors; } + int GetItemTextColor(Color customColor, ColorStateList originalColors) + { + return customColor?.ToPlatform().ToArgb() ?? originalColors?.DefaultColor ?? 0; + } + protected virtual ColorStateList GetItemIconTintColorState() { if (_orignalTabIconColors is null) diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/DefaultSelectedTabTextColorShouldApplyProperly.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/DefaultSelectedTabTextColorShouldApplyProperly.png new file mode 100644 index 000000000000..bd9bad4e2b1f Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/DefaultSelectedTabTextColorShouldApplyProperly.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue28838.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue28838.cs new file mode 100644 index 000000000000..89eb6fafb853 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue28838.cs @@ -0,0 +1,75 @@ +namespace Maui.Controls.Sample.Issues; +[Issue(IssueTracker.Github, 28838, "Incorrect Text Color Applied to Selected Tab in TabbedPage on Android", PlatformAffected.Android)] +public class Issue28838 : TabbedPage +{ + public Issue28838() + { + // Set the UnselectedTabColor property , it should be applied only to the unselected tab. + UnselectedTabColor = Colors.Red; + + // Add tabs (pages) + Children.Add(new Issue28838Tab1()); + Children.Add(new Issue28838Tab2()); + Children.Add(new Issue28838Tab3()); + } +} + +public class Issue28838Tab1 : ContentPage +{ + public Issue28838Tab1() + { + Title = "Tab 1"; + var verticalStackLayout = new VerticalStackLayout + { + VerticalOptions = LayoutOptions.Center, + Children = { + new Label + { + HorizontalOptions = LayoutOptions.Center, + Text = "Tab 1", + AutomationId = "Tab1" + }, + } + }; + Content = verticalStackLayout; + } +} + +public class Issue28838Tab2 : ContentPage +{ + public Issue28838Tab2() + { + Title = "Tab 2"; + var verticalStackLayout = new VerticalStackLayout + { + VerticalOptions = LayoutOptions.Center, + Children = { + new Label + { + HorizontalOptions = LayoutOptions.Center, + Text = "Tab 2" + } + } + }; + Content = verticalStackLayout; + } +} +public class Issue28838Tab3 : ContentPage +{ + public Issue28838Tab3() + { + Title = "Tab 3"; + var verticalStackLayout = new VerticalStackLayout + { + VerticalOptions = LayoutOptions.Center, + Children = { + new Label + { + HorizontalOptions = LayoutOptions.Center, + Text = "Tab 3" + } + } + }; + Content = verticalStackLayout; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/DefaultSelectedTabTextColorShouldApplyProperly.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/DefaultSelectedTabTextColorShouldApplyProperly.png new file mode 100644 index 000000000000..71dbc11004a8 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/DefaultSelectedTabTextColorShouldApplyProperly.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28838.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28838.cs new file mode 100644 index 000000000000..143b675e018e --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28838.cs @@ -0,0 +1,19 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; +public class Issue28838 : _IssuesUITest +{ + public Issue28838(TestDevice device) : base(device) { } + + public override string Issue => "Incorrect Text Color Applied to Selected Tab in TabbedPage on Android"; + + [Test] + [Category(UITestCategories.TabbedPage)] + public void DefaultSelectedTabTextColorShouldApplyProperly() + { + App.WaitForElement("Tab1"); + VerifyScreenshot(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DefaultSelectedTabTextColorShouldApplyProperly.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DefaultSelectedTabTextColorShouldApplyProperly.png new file mode 100644 index 000000000000..a3234088359e Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/DefaultSelectedTabTextColorShouldApplyProperly.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/DefaultSelectedTabTextColorShouldApplyProperly.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/DefaultSelectedTabTextColorShouldApplyProperly.png new file mode 100644 index 000000000000..a5cee42cd6f8 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/DefaultSelectedTabTextColorShouldApplyProperly.png differ