-
Notifications
You must be signed in to change notification settings - Fork 478
Add Support for NavigationBar.SetColor(Color) on Android 35+
#3057
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
Conversation
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 fixes a bug where NavigationBar.SetColor() has no effect on Android 35+. The issue was introduced when Android deprecated the Window.SetNavigationBarColor() API in version 35. The fix follows the same pattern used for the StatusBar fix in PR #2939 by creating an overlay view for Android 35+ devices.
Changes:
- Added Android 35+ support by creating a navigation bar overlay view when the deprecated API is unavailable
- Added required
Android.Widgetimport forFrameLayoutusage - Maintained backward compatibility with Android 23-34 using the original API
src/CommunityToolkit.Maui/PlatformConfiguration/AndroidSpecific/NavigationBar.android.cs
Outdated
Show resolved
Hide resolved
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
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
src/CommunityToolkit.Maui/PlatformConfiguration/AndroidSpecific/NavigationBar.android.cs
Show resolved
Hide resolved
|
|
||
| navigationBarOverlay = new(activity) | ||
| { | ||
| LayoutParameters = new FrameLayout.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, navigationBarPixelSize + 3) |
Copilot
AI
Jan 30, 2026
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 magic number + 3 added to the navigation bar height is unexplained. Consider extracting this to a named constant with a descriptive comment explaining why 3 extra pixels are needed. This would improve code maintainability and make the intent clear to future developers.
src/CommunityToolkit.Maui/PlatformConfiguration/AndroidSpecific/NavigationBar.android.cs
Show resolved
Hide resolved
…c/NavigationBar.android.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
| if (OperatingSystem.IsAndroidVersionAtLeast(35)) | ||
| { | ||
| const string navigationBarOverlayTag = "NavigationBarOverlay"; | ||
|
|
||
| WindowCompat.SetDecorFitsSystemWindows(window, false); | ||
|
|
||
| var decorGroup = (ViewGroup)window.DecorView; | ||
| var navigationBarOverlay = decorGroup.FindViewWithTag(navigationBarOverlayTag); | ||
|
|
||
| if (navigationBarOverlay is null) | ||
| { | ||
| var navigationBarHeight = activity.Resources?.GetIdentifier("navigation_bar_height", "dimen", "android") ?? 0; | ||
| var navigationBarPixelSize = navigationBarHeight > 0 ? activity.Resources?.GetDimensionPixelSize(navigationBarHeight) ?? 0 : 0; | ||
|
|
||
| navigationBarOverlay = new(activity) | ||
| { | ||
| LayoutParameters = new FrameLayout.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, navigationBarPixelSize + 3) | ||
| { | ||
| Gravity = GravityFlags.Bottom | ||
| } | ||
| }; | ||
|
|
||
| navigationBarOverlay.Tag = navigationBarOverlayTag; | ||
| decorGroup.AddView(navigationBarOverlay); | ||
| navigationBarOverlay.SetZ(0); | ||
| } | ||
|
|
||
| navigationBarOverlay.SetBackgroundColor(color); | ||
| } | ||
| else if (OperatingSystem.IsAndroidVersionAtLeast(23)) | ||
| { | ||
| window.SetNavigationBarColor(color); | ||
| } |
Copilot
AI
Jan 30, 2026
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 NavigationBar implementation is missing window flag handling for transparent colors that StatusBar includes (StatusBar.android.cs:75-85). StatusBar sets different WindowManagerFlags based on whether the color is transparent:
- For transparent:
ClearFlags(DrawsSystemBarBackgrounds)andSetFlags(LayoutNoLimits) - For non-transparent:
ClearFlags(LayoutNoLimits)andSetFlags(DrawsSystemBarBackgrounds)
Without this handling, transparent navigation bar colors may not render correctly. Consider adding similar logic to maintain consistency with StatusBar behavior and ensure proper transparent color support.
| if (OperatingSystem.IsAndroidVersionAtLeast(35)) | ||
| { | ||
| const string navigationBarOverlayTag = "NavigationBarOverlay"; | ||
|
|
Copilot
AI
Jan 30, 2026
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.
This line has trailing whitespace after the semicolon. Remove the trailing whitespace to maintain code cleanliness.
Description of Change
This PR adds support for
NavigationBar.SetColor(Color)on Android 35+.This bug was introduced in Android 35+ when they deprecated the
Window.SetNavigationBarColor()API that we were using to set the Navigation Bar Color:Maui/src/CommunityToolkit.Maui/PlatformConfiguration/AndroidSpecific/NavigationBar.android.cs
Line 100 in a63844e
Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
This demo shows it now working on an Android API 36.1 Emulator:
The fix for this is similar to the 35.0+ bug fixed for
StatusBarin #2939