Huby03
Huby03

Reputation: 801

Xamarin Forms background image with transparent status bar

I've been trying to create the following layout in Xamarin Forms, a background image with a transparent status bar:

Image with transparent status bar

I want to have a background image with a transparent status bar like the image above. My issues are:

  1. I am unable to do this on Android while on iOS it's good. I've tried to set my status bar transparent and did it programmatically as well, it seems that my image just don't get behind the status bar.. I didn't found any relevant information on internet about it, only to change the AppTheme information which i did but is not working.

  2. On iOS, the status bar text color is black and as well am unable to change it to white.

I've spend two weeks trying to found out how to do it but am still unable to do it.. Should i create a custom renderer for this? Or is there a much more simpler way to do it?

Upvotes: 1

Views: 3744

Answers (2)

Ivan I
Ivan I

Reputation: 9990

This looks like to be using this code in styles.xml:

<item name="android:windowTranslucentStatus">true</item>

Upvotes: 6

Manish Sharma
Manish Sharma

Reputation: 2426

You can use this solution and apply color.

In new Android.Graphics.Color(18, 52, 86, 255) you can pass RGBA for color.

Add this code Before LoadApplication() in MainActivity

if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
            Window.DecorView.SystemUiVisibility = 0;
            var statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            statusBarHeightInfo.SetValue(this, 0);
            Window.SetStatusBarColor(new Android.Graphics.Color(18, 52, 86, 255));
}

Add This code after LoadApplication() in MainActivity

App.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);

Upvotes: 4

Related Questions