Reputation: 1280
I'm looking for a way to turn Android StatusBar completely transparent with Xamarin Forms. I can easily make it semitransparent by setting android:windowTranslucentStatus
to true
. It will be black with an opacity of about 50% but anyway its background will be visible, which is not what I want.
I found this article, and this is exactly what I need as a result
https://learnpainless.com/android/material/make-fully-android-transparent-status-bar
but the problem is that there seems to be no obvious way to achieve the same in Xamarin Forms. I just haven't found a way to set decor flags like that nor a way to do this in styles.xml
I've also seen this topic (which was suggested to me while I was creating mine) Android transparent status bar and actionbar and googled this one Xamarin Forms background image with transparent status bar and several others. But all those solutions end up with a semitransparent status bar as well. So I'm completely stuck with this
Upvotes: 2
Views: 2296
Reputation: 1280
I've just found an easy solution. I just need to set a colorPrimaryDark with alpha component. I was setting alpha component at the end of a hex value (like on android) but I needed to set it at the begining in xamarin. So the solution is like this:
<item name="colorPrimaryDark">@color/statusTransparent</item>
And the color itself (in colors.xml) is
<color name="statusTransparent">#26ff9b76</color>
Where 26 is the HEX alpha component. Which means 15% alpha, but if I change it to 00 I get fully transparent status bar I got the values here Hex transparency in colors
Well, it's not a completely working solution. Even though the status bar turns transparent, xamarin doesn't draw its pages under this status bar, only the activity's background is visible
The only way to make xamarin draw its contents under the status bar is to make it semitransparent via android:windowTranslucentStatus
But in this case it looks like this:
And it's not what I want. So the question is still open
Upvotes: 1
Reputation: 700
You can do this in the OnCreate method of MainActivity.cs
This will remove the status bar from all screens.
// On Create in the activity
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
this.Window.ClearFlags(WindowManagerFlags.Fullscreen);
SetContentView (Resource.Layout.YourLayout);
}
if you want for both platforms, I would prefer you do it in the code behind file :
public partial class MyPage : ContentPage
{
public MyPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
}
Upvotes: 0