Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms Android transparent status bar

I have created a Xamarin Forms project and i am unable to change my Android status bar color to transparent. I am changing my colors programmatically in the OnCreate() method of my MainActivity as follow:

  if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
        {
            Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
            Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            Window.SetStatusBarColor(Color.Transparent);
        }

I tried different colors and it's working fine but "Transparent" is not working at all. I am testing on an API 22.

My style.xml is as follow:

  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/blue</item>
    <item name="colorPrimaryDark">@color/blue</item>
    <item name="colorAccent">#FF4081</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>

If i set programmatically my color to Purple for example it will work without issue, but if I set it to Transparent, i will get my style.xml color which is blue. If i remove my style.xml ColorPrimaryDark color, i get a gray status bar. What could be the solution?

like image 982
Huby03 Avatar asked Dec 23 '22 18:12

Huby03


2 Answers

Did you try this ?

<item name="android:windowTranslucentStatus">true</item>
like image 181
Thomas Montagnoni Avatar answered Jan 09 '23 05:01

Thomas Montagnoni


You can try adding this in styles.xml (Android proj)

<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
   <item name="android:statusBarColor">@android:color/transparent</item>
   <item name="android:windowTranslucentStatus">true</item>
</style>

Looks something like this:-

enter image description here

like image 32
user10398433 Avatar answered Jan 09 '23 04:01

user10398433