Skip to content
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

Unable to change color of SearchBar magnifying glass icon #6094

Open
emorell96 opened this issue Apr 14, 2022 · 12 comments · May be fixed by #26759
Open

Unable to change color of SearchBar magnifying glass icon #6094

emorell96 opened this issue Apr 14, 2022 · 12 comments · May be fixed by #26759

Comments

@emorell96
Copy link

Description

image
The magnifying glass in SearchBar cannot be changed using Styles in XAML. This feels like a forgotten detail. The cancel button can be changed but not this which means that in Dark Mode you cannot see it.

Steps to Reproduce

  1. Create a MAUI project.
  2. Try to change the color of the magnifying glass.
  3. Not possible.

Version with bug

Release Candidate 1 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

API 30, Android 11

Did you find any workaround?

I can change the background using a handler, but I cannot change the magnifying glass looks through a handler AFAIK.

Relevant log output

No response

@emorell96 emorell96 added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Apr 14, 2022
@jfversluis
Copy link
Member

Correct, this was inherited from Xamarin.Forms. We have an open PR here that makes the icon the same color as the text color. Would that make sense for you, or would you want to set it separately?

@jfversluis jfversluis added legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor area-controls-entry Entry and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Apr 14, 2022
@jfversluis jfversluis added this to the 6.0.300-servicing milestone Apr 14, 2022
@emorell96
Copy link
Author

I think it's fine for me but I'm sure that people would appreciate the freedom of setting the color independently from the text color but defaulting to be the same color.

@jsuarezruiz jsuarezruiz added t/enhancement ☀️ New feature or request and removed t/bug Something isn't working labels Apr 18, 2022
@emorell96
Copy link
Author

For anyone who might stumble to this issue. I've found a brute force way of setting the color on every Search Bar:

Microsoft.Maui.Handlers.SearchBarHandler.Mapper.AppendToMapping("LightSearch", (h, v) =>
        {

            var children = h.PlatformView.GetChildrenOfType<ImageView>();
            foreach(var child in children)
            {
                child.SetColorFilter(Colors.DarkGray.ToPlatform());
            }
            
            
        });

I tried doing it like they do in here: xamarin/Xamarin.Forms#14766 but that didn't work because the imageview wouldn't be found inside the PlatformView. So instead I just iterate through all the imageview inside the search bar and I set its color filter.

@Redth Redth modified the milestones: 6.0-servicing, Backlog Aug 30, 2022
@ghost
Copy link

ghost commented Aug 30, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@jfversluis jfversluis changed the title There's no way AFAIK of changing the color of the magnifying glass in SearchBar Unable to change color of SearchBar magnifying glass icon Mar 18, 2023
@Cybrosys
Copy link

Any update on this?

@AlleSchonWeg
Copy link
Contributor

AlleSchonWeg commented Jan 15, 2024

Hi,
do you know how to change the color of the search_plate? Search_plate is the line under the text. In XF this code works:

		var plate = Control.FindViewById(Resources.GetIdentifier("android:id/search_plate", null, null));
		plate.Background.SetColorFilter(new BlendModeColorFilter(Color.YellowGreen, BlendMode.Multiply));

With maui:

				var plate = handler.PlatformView.FindViewById(Platform.AppContext.Resources.GetIdentifier("android:id/search_plate", null, null));
				plate.Background.SetColorFilter(new BlendModeColorFilter(col, BlendMode.Multiply));

FindViewById returns null. Platform.AppContext.Resources.GetIdentifier("android:id/search_plate", null, null) returns 16909479 as identifier.

Edit: I found a solution:

		var icon = handler.PlatformView.FindViewById<ImageView>(ResourceConstant.Id.search_mag_icon);
		icon?.SetColorFilter(col);
		var plate = handler.PlatformView.FindViewById(ResourceConstant.Id.search_plate);
		plate?.Background?.SetColorFilter(new BlendModeColorFilter(col, BlendMode.Multiply));

@Equabyte
Copy link

Can anyone please confirm when is this fix planned for release? The magnifying glass icon color should (at least) match text color or (best) have its own bindable property; switching the app theme from light to dark or vice versa makes the magnifying glass become invisible which is not good at all. Also we should not be forced to use handlers for something like this.

@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@smstosandeep

This comment has been minimized.

@JairoMarques

This comment has been minimized.

@ALJASAC

This comment has been minimized.

@dylix
Copy link

dylix commented Aug 29, 2024

@jfversluis Crazy that this is still an issue..

@LeeroyGgJenkins

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet