Skip to content

Conversation

@TheCodeTraveler
Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler commented Jan 30, 2026

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:

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard

Additional information

This demo shows it now working on an Android API 36.1 Emulator:

ScreenFlow

The fix for this is similar to the 35.0+ bug fixed for StatusBar in #2939

Copy link
Contributor

Copilot AI left a 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.Widget import for FrameLayout usage
  • Maintained backward compatibility with Android 23-34 using the original API

Copy link
Contributor

Copilot AI left a 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.


navigationBarOverlay = new(activity)
{
LayoutParameters = new FrameLayout.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, navigationBarPixelSize + 3)
Copy link

Copilot AI Jan 30, 2026

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.

Copilot uses AI. Check for mistakes.
…c/NavigationBar.android.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 30, 2026 10:30
Copy link
Contributor

Copilot AI left a 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.

Comment on lines +99 to 131
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);
}
Copy link

Copilot AI Jan 30, 2026

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) and SetFlags(LayoutNoLimits)
  • For non-transparent: ClearFlags(LayoutNoLimits) and SetFlags(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.

Copilot uses AI. Check for mistakes.
if (OperatingSystem.IsAndroidVersionAtLeast(35))
{
const string navigationBarOverlayTag = "NavigationBarOverlay";

Copy link

Copilot AI Jan 30, 2026

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.

Suggested change

Copilot uses AI. Check for mistakes.
@TheCodeTraveler TheCodeTraveler enabled auto-merge (squash) January 30, 2026 10:38
@TheCodeTraveler TheCodeTraveler merged commit cdf9fa5 into main Jan 30, 2026
15 of 16 checks passed
@TheCodeTraveler TheCodeTraveler deleted the Fix-NavigationBar-on-Android-35 branch January 30, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Android 35+: NavigationBar.SetColor has no effect

2 participants