-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] SearchBar does not update colors on theme change - fix #30601
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
base: main
Are you sure you want to change the base?
Conversation
Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that the Android SearchBar’s placeholder, text, and cancel‐button colors correctly update when the app’s theme changes.
- Update
SearchViewExtensions
to pull hint/text colors from the current Android theme. - Hook into
Application.RequestedThemeChanged
inSearchBar
to reapply color properties. - Extend the Android handler mapping to call the new text‐color update logic.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
src/Core/src/Platform/Android/SearchViewExtensions.cs | Read hint/text colors from theme and apply on placeholder, text, and cancel button |
src/Core/src/Handlers/SearchBar/SearchBarHandler.Android.cs | Invoke UpdateTextColor on the platform view as well as the query editor |
src/Controls/src/Core/SearchBar/SearchBar.cs | Subscribe/unsubscribe to theme‐change events and trigger property updates |
src/Controls/src/Core/Application/Application.cs | Move UserAppTheme property‐changed notification before raising the RequestedThemeChanged event |
Comments suppressed due to low confidence (1)
src/Controls/src/Core/SearchBar/SearchBar.cs:134
- There are no automated UI tests covering the dynamic theme‐change behavior for Android SearchBar. Please add a HostApp UI page and corresponding NUnit tests in TestCases.Shared.Tests to validate that placeholder, text, and cancel‐button colors update correctly.
private void OnRequestedThemeChanged(object sender, AppThemeChangedEventArgs e)
editText.Resources?.GetColor(typedValue.ResourceId, theme) is Color textColorHint) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern matching GetColor(...) is Color textColorHint
will never match because GetColor
returns an int, not an Android.Graphics.Color. You should capture the returned int and construct a Color (e.g., new Color(resources.GetColor(...))
) before applying it.
editText.Resources?.GetColor(typedValue.ResourceId, theme) is Color textColorHint) | |
{ | |
editText.Resources?.GetColor(typedValue.ResourceId, theme) is int colorInt) | |
{ | |
var textColorHint = new Color(colorInt); |
Copilot uses AI. Check for mistakes.
editText.Resources?.GetColor(typedValue.ResourceId, theme) is Color color) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue here: GetColor
returns an int, so the is Color color
check will fail. Use the returned int to create an Android.Graphics.Color instance before calling SetTextColor
.
editText.Resources?.GetColor(typedValue.ResourceId, theme) is Color color) | |
{ | |
editText.Resources?.GetColor(typedValue.ResourceId, theme) is int colorInt) | |
{ | |
var color = Color.ValueOf(colorInt); |
Copilot uses AI. Check for mistakes.
theme.ResolveAttribute(Android.Resource.Attribute.TextColorPrimary, typedValue, true) && | ||
image.Resources?.GetColor(typedValue.ResourceId, theme) is Color imageColor) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expression GetColor(...) is Color imageColor
will never succeed since GetColor
returns an int. Construct an Android.Graphics.Color
from the int result to apply the tint correctly.
theme.ResolveAttribute(Android.Resource.Attribute.TextColorPrimary, typedValue, true) && | |
image.Resources?.GetColor(typedValue.ResourceId, theme) is Color imageColor) | |
{ | |
theme.ResolveAttribute(Android.Resource.Attribute.TextColorPrimary, typedValue, true)) | |
{ | |
var colorInt = image.Resources?.GetColor(typedValue.ResourceId, theme) ?? 0; | |
var imageColor = Color.ValueOf(colorInt); |
Copilot uses AI. Check for mistakes.
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
if (Application.Current == null) | ||
return; | ||
|
||
if (args.NewHandler == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're only unsubscribing when NewHandler
is null, but you should unsubscribe whenever there's an OldHandler
.
{ | ||
App.WaitForElement("changeThemeButton"); | ||
App.Tap("changeThemeButton"); | ||
VerifyScreenshot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending snapshots, running a build.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issues Fixed
Fixes #30600
Fixes #25153
Screen.Recording.2025-07-13.at.19.44.33.mov
Screen.Recording.2025-07-13.at.19.36.48.mov