Skip to content

Commit cf6e3de

Browse files
Ahamed-AliPureWeen
authored andcommitted
[Android] Fixed the Incorrect Text Color Applied to Selected Tab in TabbedPage (#28844)
* Fixed the Incorrect Text Color Applied to Selected Tab in TabbedPage on Android * Added pending snap and optimized the fix
1 parent 3e72a26 commit cf6e3de

File tree

7 files changed

+103
-12
lines changed

7 files changed

+103
-12
lines changed

src/Controls/src/Core/Platform/Android/TabbedPageManager.cs

+9-12
Original file line numberDiff line numberDiff line change
@@ -635,26 +635,23 @@ protected virtual ColorStateList GetItemTextColorStates()
635635
}
636636
else
637637
{
638-
if (barItemColor is not null)
639-
defaultColor = barItemColor.ToPlatform().ToArgb();
638+
// UnSelected tabs TextColor
639+
defaultColor = GetItemTextColor(barItemColor, _originalTabTextColors);
640640

641-
if (barItemColor is null && _originalTabTextColors is not null)
642-
defaultColor = _originalTabTextColors.DefaultColor;
643-
644-
if (!defaultColor.HasValue)
645-
return _originalTabTextColors;
646-
else
647-
checkedColor = defaultColor.Value;
648-
649-
if (barSelectedItemColor is not null)
650-
checkedColor = barSelectedItemColor.ToPlatform().ToArgb();
641+
// Selected tabs TextColor
642+
checkedColor = GetItemTextColor(barSelectedItemColor, _originalTabTextColors);
651643
}
652644

653645
_newTabTextColors = GetColorStateList(defaultColor.Value, checkedColor);
654646

655647
return _newTabTextColors;
656648
}
657649

650+
int GetItemTextColor(Color customColor, ColorStateList originalColors)
651+
{
652+
return customColor?.ToPlatform().ToArgb() ?? originalColors?.DefaultColor ?? 0;
653+
}
654+
658655
protected virtual ColorStateList GetItemIconTintColorState()
659656
{
660657
if (_orignalTabIconColors is null)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
[Issue(IssueTracker.Github, 28838, "Incorrect Text Color Applied to Selected Tab in TabbedPage on Android", PlatformAffected.Android)]
3+
public class Issue28838 : TabbedPage
4+
{
5+
public Issue28838()
6+
{
7+
// Set the UnselectedTabColor property , it should be applied only to the unselected tab.
8+
UnselectedTabColor = Colors.Red;
9+
10+
// Add tabs (pages)
11+
Children.Add(new Issue28838Tab1());
12+
Children.Add(new Issue28838Tab2());
13+
Children.Add(new Issue28838Tab3());
14+
}
15+
}
16+
17+
public class Issue28838Tab1 : ContentPage
18+
{
19+
public Issue28838Tab1()
20+
{
21+
Title = "Tab 1";
22+
var verticalStackLayout = new VerticalStackLayout
23+
{
24+
VerticalOptions = LayoutOptions.Center,
25+
Children = {
26+
new Label
27+
{
28+
HorizontalOptions = LayoutOptions.Center,
29+
Text = "Tab 1",
30+
AutomationId = "Tab1"
31+
},
32+
}
33+
};
34+
Content = verticalStackLayout;
35+
}
36+
}
37+
38+
public class Issue28838Tab2 : ContentPage
39+
{
40+
public Issue28838Tab2()
41+
{
42+
Title = "Tab 2";
43+
var verticalStackLayout = new VerticalStackLayout
44+
{
45+
VerticalOptions = LayoutOptions.Center,
46+
Children = {
47+
new Label
48+
{
49+
HorizontalOptions = LayoutOptions.Center,
50+
Text = "Tab 2"
51+
}
52+
}
53+
};
54+
Content = verticalStackLayout;
55+
}
56+
}
57+
public class Issue28838Tab3 : ContentPage
58+
{
59+
public Issue28838Tab3()
60+
{
61+
Title = "Tab 3";
62+
var verticalStackLayout = new VerticalStackLayout
63+
{
64+
VerticalOptions = LayoutOptions.Center,
65+
Children = {
66+
new Label
67+
{
68+
HorizontalOptions = LayoutOptions.Center,
69+
Text = "Tab 3"
70+
}
71+
}
72+
};
73+
Content = verticalStackLayout;
74+
}
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
public class Issue28838 : _IssuesUITest
7+
{
8+
public Issue28838(TestDevice device) : base(device) { }
9+
10+
public override string Issue => "Incorrect Text Color Applied to Selected Tab in TabbedPage on Android";
11+
12+
[Test]
13+
[Category(UITestCategories.TabbedPage)]
14+
public void DefaultSelectedTabTextColorShouldApplyProperly()
15+
{
16+
App.WaitForElement("Tab1");
17+
VerifyScreenshot();
18+
}
19+
}

0 commit comments

Comments
 (0)