remove top bar on Android with xamarin forms
Asked Answered
M

5

5

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>
Mouse answered 26/1, 2017 at 9:2 Comment(2)
Have you tried to add this to your Activity? [Activity (Label = "@string/app_name", MainLauncher = true, Theme = "@android:style/Theme.Black.NoTitleBar.Fullscreen")]Blackstone
yes but don't work, the top bar is not hideMouse
A
7
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());
    }
}
Arlina answered 12/3, 2017 at 11:44 Comment(1)
You should definitely include some description of what is it your code does.Fleer
S
2

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.

Slipsheet answered 8/9, 2022 at 1:42 Comment(0)
W
1
 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.

Wendiewendin answered 28/9, 2017 at 15:57 Comment(0)
A
0

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>
Allantoid answered 26/1, 2017 at 15:41 Comment(9)
This is the official way to do this. Something else must be messed up with our theme. Can you add your full theme in your styles.xml?Allantoid
maybe i don't add official theme ? how i do check if add the theme ?Mouse
Can you just paste what is in your styles.xml?Allantoid
What? I just want to see your styles.xml. Open your styles.xml, Ctrl + a, Ctrl + c, come back here, add comment, Ctrl + v, enterAllantoid
No resource found that matches the given name: attr 'windowFullscreen'. how to add ? sorry i'm beginner in xamarin :(Mouse
You don't have a theme called "@style/MainTheme.FullScreen"... That's why it isn't being applied. That isn't a theme. Either in your Activity attribute set it to "@style/MainTheme" or in your styles change MainTheme to MainTheme.FullScreenAllantoid
@Mr.Developer I'll edit my answer with what you should change your styles toAllantoid
Visual studio response me like this: Java.Lang.IllegalArgumentException: AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: true, windowNoTitle: false }Mouse
are you using windowNoTitle or android:windowNoTitle? Same with the windowFullscreen; should be android:windowFullscreenAllantoid
B
0

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>
Bryce answered 21/8, 2019 at 15:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.