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
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public Color TintColor
_tintColor = value;
if (Page != null)
{
UpdateToolbarItems();
UpdateToolbarItemsTintColors();
UpdateLeftBarButtonItem();
}
}
Expand Down Expand Up @@ -628,9 +628,21 @@ protected virtual void UpdateTitleView(Context context, AToolbar toolbar, View t
_toolbar.Handler?.UpdateValue(nameof(Toolbar.TitleView));
}

private void UpdateToolbarItemsTintColors(AToolbar toolbar)
{
var menu = toolbar.Menu;
int _placeholderMenuItemId = 100;
if (menu.FindItem(_placeholderMenuItemId) is IMenuItem item)
{
using (var icon = item.Icon)
icon.SetColorFilter(TintColor.ToPlatform(Colors.White), FilterMode.SrcAtop);
Copy link

Copilot AI May 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The color filter is hard-coded to white (using Colors.White) instead of the actual TintColor; you should apply the intended TintColor (e.g., TintColor.ToPlatform()) to respect the configured tint.

Suggested change
icon.SetColorFilter(TintColor.ToPlatform(Colors.White), FilterMode.SrcAtop);
icon.SetColorFilter((TintColor?.ToPlatform() ?? Colors.White.ToPlatform()), FilterMode.SrcAtop);

Copilot uses AI. Check for mistakes.
}
}

protected virtual void UpdateToolbarItems(AToolbar toolbar, Page page)
{
var menu = toolbar.Menu;
int _placeholderMenuItemId = 100;
SearchHandler = Shell.GetSearchHandler(page);
if (SearchHandler != null && SearchHandler.SearchBoxVisibility != SearchBoxVisibility.Hidden)
{
Expand All @@ -650,7 +662,7 @@ protected virtual void UpdateToolbarItems(AToolbar toolbar, Page page)
if (SearchHandler.SearchBoxVisibility == SearchBoxVisibility.Collapsible)
{
var placeholder = new Java.Lang.String(SearchHandler.Placeholder);
var item = menu.Add(placeholder);
var item = menu.Add(0, _placeholderMenuItemId, 0, placeholder);
placeholder.Dispose();

item.SetEnabled(SearchHandler.IsSearchEnabled);
Expand Down Expand Up @@ -725,6 +737,11 @@ void UpdateToolbarItems()
UpdateToolbarItems(_platformToolbar, Page);
}

void UpdateToolbarItemsTintColors()
{
UpdateToolbarItemsTintColors(_platformToolbar);
}

class FlyoutIconDrawerDrawable : DrawerArrowDrawable
{
public Drawable IconBitmap { get; set; }
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29499.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 29499, "[Android] The number of SearchHandler toolbar item increases abnormally", PlatformAffected.Android)]
public class Issue29499 : Shell
{
public Issue29499()
{
Routing.RegisterRoute(nameof(Issue29499Subpage), typeof(Issue29499Subpage));
Items.Add(new Issue29499Page());
}

public class Issue29499Page : ContentPage
{
public Issue29499Page()
{
SetForegroundColor(this, Colors.Red);
ToolbarItems.Add(new ToolbarItem { Text = "Item1", Order = ToolbarItemOrder.Secondary });
ToolbarItems.Add(new ToolbarItem { Text = "Item2", Order = ToolbarItemOrder.Secondary });
ToolbarItems.Add(new ToolbarItem { Text = "Item3", Order = ToolbarItemOrder.Secondary });
ToolbarItems.Add(new ToolbarItem { Text = "Item4", Order = ToolbarItemOrder.Secondary });
SetSearchHandler(this, new MainSearchHandler { SearchBoxVisibility = SearchBoxVisibility.Collapsible });
Content = new Button
{
Text = "Go to subpage page",
AutomationId = "GotoIssue29499Subpage",
Command = new Command(async () =>
{
await Current.GoToAsync(nameof(Issue29499Subpage));
})
};
}

public class MainSearchHandler : SearchHandler { }
}

public class Issue29499Subpage : ContentPage
{
public Issue29499Subpage()
{
Content = new StackLayout
{
Children =
{
new Button
{
Text = "Go back",
AutomationId = "GoBackButton",
Command = new Command(async () =>
{
await Current.GoToAsync("..");
})
},
}
};
}
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if ANDROID
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue29499 : _IssuesUITest
{
public Issue29499(TestDevice testDevice) : base(testDevice) { }

public override string Issue => "[Android] The number of SearchHandler toolbar item increases abnormally";

[Test]
[Category(UITestCategories.SearchBar)]
public void NumberOfToolbarItemsShouldNotIncrease()
{
App.WaitForElement("GotoIssue29499Subpage");
App.Click("GotoIssue29499Subpage");
App.WaitForElement("GoBackButton");
App.Click("GoBackButton");
App.WaitForElement("GotoIssue29499Subpage");
((AppiumApp)App).Driver.FindElement(OpenQA.Selenium.By.XPath("//*[@content-desc=\"More options\"]")).Click();
VerifyScreenshot();
}
}
#endif
Loading