Skip to content

[android] Fallback to default icons in SearchHandler #25067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
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 @@ -11,8 +11,8 @@
using Android.Widget;
using AndroidX.AppCompat.Widget;
using AndroidX.CardView.Widget;
using AndroidX.Core.Content;
using Java.Lang;
using Microsoft.Maui.Controls.Platform.Compatibility;
using AColor = Android.Graphics.Color;
using AImageButton = Android.Widget.ImageButton;
using ASupportDrawable = AndroidX.AppCompat.Graphics.Drawable;
Expand Down Expand Up @@ -317,12 +317,22 @@ AImageButton CreateImageButton(Context context, BindableObject bindable, Bindabl
result.SetScaleType(ImageView.ScaleType.FitCenter);

if (bindable.GetValue(property) is ImageSource image)
{
AutomationPropertiesProvider.SetContentDescription(result, image, null, null);

((ImageSource)bindable.GetValue(property)).LoadImage(MauiContext, (r) =>
image.LoadImage(MauiContext, (r) =>
{
result.SetImageDrawable(r?.Value);
});
}
else if (defaultImage > 0 && ContextCompat.GetDrawable(Context, defaultImage) is Drawable defaultDrawable)
{
result.SetImageDrawable(r?.Value);
});
result.SetImageDrawable(defaultDrawable);
}
else
{
result.SetImageDrawable(null);
}

var lp = new LinearLayout.LayoutParams((int)Context.ToPixels(22), LP.MatchParent)
{
Expand Down
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.
46 changes: 46 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25067.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue25067"
>
<TabBar>

<ShellContent Title="Default Icons" Route="DefaultIcons">
<ContentPage
Shell.TabBarIsVisible="False"
Shell.NavBarIsVisible="true">

<!-- A value for Query is required for the ClearIcon to be visible -->
<Shell.SearchHandler>
<SearchHandler Query="search" SearchBoxVisibility="Expanded" />
</Shell.SearchHandler>

<StackLayout>
<Label AutomationId="WaitForStubControl" Text="If you see a search icon (left) and clear icon (right) then the test passes."/>
<Button AutomationId="GoToDefault" Text="Go To Default Icons" Clicked="GoToDefault_Clicked"/>
<Button AutomationId="GoToCustom" Text="Go To Custom Icons" Clicked="GoToCustom_Clicked"/>
</StackLayout>
</ContentPage>
</ShellContent>

<ShellContent Title="Custom Icons" Route="CustomIcons">
<ContentPage
Shell.TabBarIsVisible="False"
Shell.NavBarIsVisible="true">

<Shell.SearchHandler>
<SearchHandler Query="search" SearchBoxVisibility="Expanded"
QueryIcon="green"
ClearIcon="red" />
</Shell.SearchHandler>

<StackLayout>
<Label AutomationId="WaitForStubControl" Text="If you see a green icon (left) and red icon (right) then the test passes."/>
<Button AutomationId="GoToDefault" Text="Go To Default Icons" Clicked="GoToDefault_Clicked"/>
<Button AutomationId="GoToCustom" Text="Go To Custom Icons" Clicked="GoToCustom_Clicked"/>
</StackLayout>
</ContentPage>
</ShellContent>

</TabBar>
</Shell>
20 changes: 20 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25067.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 25067, "[Android] SearchHandler default/custom icons", PlatformAffected.Android)]
public partial class Issue25067 : Shell
{
public Issue25067()
{
InitializeComponent();
}
private void GoToCustom_Clicked(object sender, EventArgs e)
{
GoToAsync("//CustomIcons");
}
private void GoToDefault_Clicked(object sender, EventArgs e)
{
GoToAsync("//DefaultIcons");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#if ANDROID
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue25067 : _IssuesUITest
{
public Issue25067(TestDevice device) : base(device) { }

public override string Issue => "[Android] SearchHandler default/custom icons";

[Test]
[Category(UITestCategories.Shell)]
public void SearchHandlerRendersDefaultSearchIconAndClearIcon()
{
App.WaitForElement("GoToDefault");

App.Tap("GoToDefault");

VerifyScreenshot();
}

[Test]
[Category(UITestCategories.Shell)]
public void SearchHandlerRendersCustomSearchIconAndClearIcon()
{
App.WaitForElement("GoToCustom");

App.Tap("GoToCustom");

VerifyScreenshot();
}
}
#endif
Loading