Transparent status bar color android#1630
Conversation
|
Hello @ne0rrmatrix, I remember you actually showed me how to solve the issue in Android when transparent status bar when the navbar goes down as you can see on the video demo below from second 20 to 30. However, I don't remember it, could you please give me a hand refreshing my brain on how to fix it? 😃 Status-bar-transparent-edited.mp4 |
ne0rrmatrix
left a comment
There was a problem hiding this comment.
Replace static void PlatformSetColor(Color color) with:
static void PlatformSetColor(Color color)
{
if (IsSupported)
{
Activity.Window?.SetStatusBarColor(color.ToPlatform());
if (Activity.Window is not null)
{
var platformColor = color.ToPlatform();
Activity.Window.SetStatusBarColor(platformColor);
var window = Activity.GetCurrentWindow();
bool isColorTransparent = platformColor == PlatformColor.Transparent;
if (isColorTransparent)
{
window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits);
}
else
{
window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds);
}
WindowCompat.SetDecorFitsSystemWindows(Activity.Window, !isColorTransparent);
}
}
}…s properly set as transparent
|
Thanks @ne0rrmatrix for sharing the insights. I made some improvements per our talk on Discord, and I believe this PR is now ready for review. @pictos or @brminnick, could any of you give me a hand reviewing it? please 😃 This change is only for Android. Screen.Recording.2024-07-22.at.10.36.22.a.m.mov |
ne0rrmatrix
left a comment
There was a problem hiding this comment.
Looks good to me. Let's wait for one more person to approve this.
pictos
left a comment
There was a problem hiding this comment.
It looks good for me, just one request. I also notice that you changed the tabs to spaces, I believe we still have a bot that will do a PR fixing the code style, so no need to change here, but probably you would like to look why your IDE is doing that
|
Thanks @pictos for the review. The code has been improved and formatted. I'm using Visual Studio code and for formatting, I use the builtin with VS Code in macOS. I'm not sure if I have to select another one for better formatting in C#. I will do some research next time 😃 If the PR is approved, who can help me to merge it? 😃 |
| Activity.Window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds); | ||
| } | ||
|
|
||
| WindowCompat.SetDecorFitsSystemWindows(Activity.Window, !isColorTransparent); |
There was a problem hiding this comment.
I think a check should be added here in case we already decided to SetDecorFitsSystemWindows to false (usually in MainActivity's OnCreate method) so it remains false, even if we decide to put a color to the status bar.
|
the video isn't working |
|
I'm facing a strange issue after the changes in this PR on Honor Play (COR-L29) Android API 29. This code doesn't work with the changes in the PR since CommunityToolkit.Maui 9.0.3. With CommunityToolkit.Maui 9.0.2 the code above works. I have this in MainPage.xaml |
| bool isColorTransparent = platformColor == PlatformColor.Transparent; | ||
| if (isColorTransparent) | ||
| { | ||
| Activity.Window.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); |
There was a problem hiding this comment.
What's the point to call ClearFlags() if this call is followed by SetFlags() which replaces all the flags?
I think I have a bug because of this
There was a problem hiding this comment.
I believe instead if SetFlags() it should be AddFlags()
There was a problem hiding this comment.
The bug i'm taking about #1630 (comment)
Description of Change
Fixes the issue with the transparent color set on the status bar for Android. This is a draft, since I'm facing a weird issue on Android eventually when the status bar is set to transparent the Shell Navigation Title is moved some points down the screen. This error occurs on Shell and non-Shell pages in .NET MAUI 8.0.3. I'm not sure if this is an issue with the way we set the transparent color or if it is an issue on the .NET MAUI. I could not find a report of this issue on the MAUI repo.
Any tip or idea is always welcome! Thank you so much!
Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRUpdated Sample
The sample has been updated to add support for Alpha values of the status bar.
Status-bar-transparent-edited.mp4