-
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
Shell Title View Overlaps Status Bar on Android when Layout Limits removed #24694
Comments
Hi I'm an AI powered bot that finds similar issues based off the issue title. Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you! Open similar issues:
Closed similar issues:
|
If you need help with the "safe areas" to move the title or shell view down, you can use the following code snippet: public Thickness SafeAreaPadding
{
get
{
if (OperatingSystem.IsAndroidVersionAtLeast(21))
{
var insets = ViewCompat.GetRootWindowInsets(Platform.CurrentActivity.Window.DecorView);
var systemBarAndNotchInsets =
insets.GetInsets(WindowInsetsCompat.Type.SystemBars() | WindowInsetsCompat.Type.DisplayCutout());
var density = DeviceDisplay.Current.MainDisplayInfo.Density;
return new Thickness(systemBarAndNotchInsets.Left / density, systemBarAndNotchInsets.Top / density,
systemBarAndNotchInsets.Right / density, systemBarAndNotchInsets.Bottom * density);
}
//todo: older stuff...
}
} |
I am not sure what the issue is here. You are removing the status bar and making the content fill the screen. That appears to be what is happening? Can you show what happened in Xamarin.Forms that is not happening in MAUI? Also, what are you expecting to happen when you remove the layout limits? I know it is a bit of a pain, but since you have the sample project already to take the screenshots, could you attach it to the issue to make debugging easier for the people that will be testing this issue? |
The status bar is not "removed", but it's no longer pushing the content down. I expect the TitleView/NavigationBar Text to be pushed down like it would be on iOS. See this closed issue from Xamarin.forms: |
That PR is using the translucent flags, you are requesting no status bar. What happens if you use the translucent flag instead? |
Then the status bar pushes the content down. I do want content to appear under the status bar for certain pages, and then content I control I do accomodate for, similar to how you have to accomodate content around the status bar on iOS. The Shell Navigation Bar should have the background fill behind the status bar with the text showing below it. If you're wondering where this is coming from, it's because the Community Toolkit allows you to set the Status Bar color as transparent, I just tried to dial down exactly why the issue is happening. I don't think the issue is with the Toolkit, it's just that MAUI is not accomading this edge case, which will be even MORE apparent come android 15 when edge-to-edge will be the default. |
I managed to find the following work-a-round: using Microsoft.Extensions.Logging;
#if ANDROID
using Microsoft.Maui.LifecycleEvents;
using Android.Views;
using AndroidX.Core.View;
using Google.Android.Material.AppBar;
#endif
namespace ShellTitleNavBug;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
#if ANDROID
.ConfigureLifecycleEvents(lifecycleBuilder =>
{
lifecycleBuilder.AddAndroid(a =>
a.OnCreate((activity, state) =>
{
activity.Window?.AddFlags(WindowManagerFlags.LayoutNoLimits);
})
);
})
.ConfigureMauiHandlers(handlers =>
{
Microsoft.Maui.Handlers.ToolbarHandler.Mapper.AppendToMapping("CustomNavigationView", (handler, view) =>
{
var toolbar = handler.PlatformView;
//Listener doesn't seem to work with toolbar, so use the main window's decor view instead
ViewCompat.SetOnApplyWindowInsetsListener(Platform.CurrentActivity.Window.DecorView, new ToolbarCustomListener(toolbar));
});
})
#endif
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
#if ANDROID
private class ToolbarCustomListener : Java.Lang.Object, IOnApplyWindowInsetsListener
{
private MaterialToolbar _toolbar;
private int _defaultPaddingLeft;
private int _defaultPaddingTop;
private int _defaultPaddingRight;
private int _defaultPaddingBottom;
private int _defaultMinHeight;
public ToolbarCustomListener(MaterialToolbar toolbar)
{
_toolbar = toolbar;
_defaultPaddingLeft = _toolbar.PaddingLeft;
_defaultPaddingTop = _toolbar.PaddingTop;
_defaultPaddingRight = _toolbar.PaddingRight;
_defaultPaddingBottom = _toolbar.PaddingBottom;
_defaultMinHeight = _toolbar.MinimumHeight;
}
public WindowInsetsCompat OnApplyWindowInsets(Android.Views.View v, WindowInsetsCompat insets)
{
var systemInsets =
insets.GetInsets(WindowInsetsCompat.Type.StatusBars() | WindowInsetsCompat.Type.DisplayCutout());
_toolbar.SetPadding(_defaultPaddingLeft, _defaultPaddingTop + systemInsets.Top, _defaultPaddingRight, _defaultPaddingBottom);
_toolbar.LayoutParameters.Height = _defaultMinHeight + systemInsets.Top;
return WindowInsetsCompat.Consumed;
}
}
#endif
} |
To avoid "Edge to Edge" Android 35, I just created this class: public class WindowInsetsHandler : Java.Lang.Object, IOnApplyWindowInsetsListener
{
public WindowInsetsCompat OnApplyWindowInsets(Android.Views.View view, WindowInsetsCompat insets)
{
var systemBars = insets.GetInsets(WindowInsetsCompat.Type.SystemBars());
view.SetPadding(view.PaddingLeft, systemBars.Top, view.PaddingRight, systemBars.Bottom);
return insets;
}
} And, added this to MainActivity OnCreate: ...
WindowCompat.SetDecorFitsSystemWindows(this.Window, false);
ViewCompat.SetOnApplyWindowInsetsListener(this.Window.DecorView, new WindowInsetsHandler());
... |
If you use Mopups then consider adding this to derived PopupPage constructor, otherwise padding is added twice - to the page and to popup:
|
Description
When Android settings remove status bar from the layout (i.e. a transparent status bar similar to iOS), the Shell Title Text is either uncomfortably close or overlaps.
Steps to Reproduce
Link to public reproduction project repository
None. Simple enough to create from starting template.
Version with bug
8.0.82 SR8.2
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
None, other than a custom title view with padding, but would prefer to stick with defaults.
Screenshots
The text was updated successfully, but these errors were encountered: