Mr. Developer
Mr. Developer

Reputation: 3417

remove top bar on Android with xamarin forms

I tried several solutions including:

<item name="android:actionBarSize">0dp</item>

or

var activity = (Activity)Forms.Context;
this.Window.AddFlags(WindowManagerFlags.Fullscreen);

or

RequestWindowFeature(WindowFeatures.NoTitle);

or in activity string

Theme = "@style/MainTheme.FullScreen"

But I could not find any solution that works, or rather, removes me the lyrics, the battery time etc., but I remain the same the top bar, how can I remove it completely?

enter image description here

on iOs i have added:

UIApplication.SharedApplication.SetStatusBarHidden(true, true);

and works...but android he is making me damn :) Solution ?

I use xamarin forms pcl

my styles.xaml

    <?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="MainTheme" parent="MainTheme.Base">
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#2196F3</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <!--<item name="colorPrimaryDark">#0084CA</item>-->
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#2196F3</item>
    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>
    <!-- default -->
    <item name="android:buttonStyle">@style/NoShadowButton</item>

    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
  </style>

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#2196F3</item>
  </style>
  <style name="NoShadowButton" parent="android:style/Widget.Button">
    <item name="android:stateListAnimator">@null</item>
  </style>
</resources>

Upvotes: 5

Views: 6332

Answers (5)

DannyD
DannyD

Reputation: 21

In a navigation page. Not in a device specific project, I set the property on the navigation page like this.

    class Page: ContentPage
    public Page()
    {
        // removes the banner from the top of the page.
        NavigationPage.SetHasNavigationBar(this, false);
    ...
    }

This also works from inside any method in the class.

Upvotes: 2

AccountForWorks
AccountForWorks

Reputation: 91

In my case it worked with this:

<?xml version="1.0" encoding="utf-8" ?>
<resources>

  <style name="MainTheme" parent="MainTheme.Base">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#2196F3</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#1976D2</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#FF4081</item>
    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>

    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
  </style>

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#FF4081</item>
  </style>
</resources>

Upvotes: 0

Alec
Alec

Reputation: 483

 if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
 {
     Window.AddFlags(WindowManagerFlags.TranslucentStatus);

     return; 
 }

This alone doesn't place the view underneath the status bar, but rather gets rid of a black space (with a height of 20px or so) below the status bar.

Upvotes: 1

Pavlo Vasilikiv
Pavlo Vasilikiv

Reputation: 84

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {

    this.Window.AddFlags(WindowManagerFlags.Fullscreen | WindowManagerFlags.TurnScreenOn);
        if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
        {
            var stBarHeight = typeof(FormsAppCompatActivity).GetField("statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            if (stBarHeight == null)
            {
                stBarHeight = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            }
            stBarHeight?.SetValue(this, 0);
        }
        base.OnCreate(bundle);


        global::Xamarin.Forms.Forms.Init(this, bundle);

        LoadApplication(new App());
    }
}

Upvotes: 7

SuavePirate
SuavePirate

Reputation: 1513

I answered this similar question in the Xamarin forums:

Add these two items to your theme for your given activity:

<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>

https://forums.xamarin.com/discussion/comment/248555

EDIT: To make it easier for you, change your styles to this -

<resources>
  <style name="MainTheme.FullScreen" parent="MainTheme.Base">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
  </style>
  <style name="MainTheme" parent="MainTheme.Base">
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#2196F3</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <!--<item name="colorPrimaryDark">#0084CA</item>-->
    <!-- colorAccent is used as the default value for colorControlActivated
     which is used to tint widgets -->
    <item name="colorAccent">#2196F3</item>
    <!-- You can also set colorControlNormal, colorControlActivated
     colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>
    <!-- default -->
    <item name="android:buttonStyle">@style/NoShadowButton</item>

    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
  </style>

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#2196F3</item>
  </style>
  <style name="NoShadowButton" parent="android:style/Widget.Button">
    <item name="android:stateListAnimator">@null</item>
  </style>
</resources>

Upvotes: 0

Related Questions