-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
MAUI - Android Navigationbar BarBackgroundColor is not updating as per the Theme color specified. #11790
Comments
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. |
Verified this on Visual Studio Enterprise 17.7.0 Preview 1.0. Repro on Android 13.0-API33 with below Project: |
Work around. If you set the app theme color for the navigation page bar background before setting the app theme the color will update. It doesn't appear to matter what color you set the light or dark value to as long as it set to something before changing your app theme. this.SetAppThemeColor(NavigationPage.BarBackgroundProperty, Color.FromArgb("#000000"), Color.FromArgb("#000000")); |
@HaroldMac: can you elaborate a little? I'm not seeing this workaround work at all, unfortunately. |
@mattleibow - since you're in the NavigationPage space... any chance you could take a look at this one? I'm seeing the same issue as the OP on 8.0.4-nightly.9717. Thanks. |
@jfversluis is there anything you can do for us? This issue is since .net6 there, and still there is an issue. In the 'Shell World', this is not an issue (but there are other issues too). |
@reinierkops Not sure if you still want it but I figured out a workaround for this that's working for my case! You can append to the NavigationPage mapper and then force the Toolbar colour to update. Our case is a bit weird, so not sure if it will work a 100%, but something to at least get you going.
This should get hit when you update the theme. Hope it works! |
Tested it with 8.0.20-nightly.10426. The:
only updates when i close the page and open it again. I changed the theme via system settings. |
Tested with official 8.0.20 release, I got the same comportment as @AlleSchonWeg When I changes the light/dark mode (from "System" or even "manually set"), every controls in my app are correctly and automatically themed (with AppThemeBinding helps) EXCEPT the NavigationBar colors (BarBackgroundColor/BarTextColor) AND the StatusBarColor of the current page.
But if I navigate just once after changing the theme (back or add to stack or whatever...), the StatusBar&Navbar colors are correctly themed !
So my current (awful) workaround is to automatically close and navigate again to the current page... it works (but it's bad) Please, investigate and correct this "basic" for Theming |
Similar to @Stephandb but without the handler.
|
Yep, nice workaround @ojoyal (far better than mine... lighter and shorter with android platform specific call and messaging 👍) |
Building off stefandb1995’s workaound, this workaround also updates the text and icon colors. It’s not a complete workaround, since the menu button color still remains stuck on the initial theme color (so a fix for this issue is still a priority). This udpated workaround appends the mapping in the same way as the initial one: NavigationViewHandler.Mapper.AppendToMapping(NavigationPage.BarBackgroundColorProperty.PropertyName, SetToolbarColor); The method to set the colors then goes through the menu and sets the text and icon colors: static void SetToolbarColor(INavigationViewHandler handler, IStackNavigationView view) {
if (!(view is NavigationPage navigationPage && navigationPage.Window is IToolbarElement toolBarOwner &&
toolBarOwner.Toolbar?.Handler is ElementHandler<IToolbar, Google.Android.Material.AppBar.MaterialToolbar> androidToolbarHandler &&
androidToolbarHandler.PlatformView is Google.Android.Material.AppBar.MaterialToolbar materialToolbar))
return;
materialToolbar.BackgroundTintList = ColorStateList.ValueOf(Styles.AndroidNavigationBarBackgroundColor.ToRequestedThemeColor().ToPlatform());
var textColor = Styles.TextColor.ToRequestedThemeColor().ToPlatform();
materialToolbar.SetTitleTextColor(textColor);
var menu = materialToolbar.Menu;
if (menu == null) return;
for (int i = 0; i < menu.Size(); ++i) {
var item = menu.GetItem(i)!;
var oldIcon = item.Icon;
if (oldIcon != null) {
var newIcon = DrawableCompat.Wrap(oldIcon);
newIcon.SetTint(textColor);
item.SetIcon(newIcon);
}
var oldTitle = item.TitleFormatted;
if (oldTitle != null && oldTitle.Length() > 0) {
var newTitle = new SpannableString(oldTitle);
newTitle.SetSpan(new ForegroundColorSpan(textColor), 0, newTitle.Length(), 0);
item.SetTitle(newTitle);
}
}
} |
We agree that this is an important issue. As our roadmap indicates, for the near future, we are focused on:
I am marking this as a p/2 issue because it does not meet our focus areas right now, but we are constantly revisiting the backlog for important issues to address as time allows. Thank you for your patience and understanding! |
Description
Android Navigationbar BarBackgroundColor is not reflecting when the theme is changed.
Rest of the UI is updating to the theme color that is specified though AppThemeBinding.
When Naviagte to another page , suddenly navigation bar shows the theme color
Steps to Reproduce
Link to public reproduction project repository
https://github.com/febinDonz/Maui-Theme-Bug
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 11 and up
Did you find any workaround?
no
Relevant log output
No response
The text was updated successfully, but these errors were encountered: