Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Hiding the Status Bar and the Action Bar in Android App

DavidPybusDavidPybus AUMember ✭✭

Can anyone tell me how to implement this in a (Xaml) implementation of an Android app?

«1

Posts

  • BojanPanjevicBojanPanjevic USMember

    If page is not a NavigationPage, ActionBar will not be displayed.

  • DavidPybusDavidPybus AUMember ✭✭

    ContentPages still have the statusbar.

  • DavidPybusDavidPybus AUMember ✭✭

    James,
    Your solution would be perfect if I could make it work!
    However, if I do what you say, I get a compilation error telling me that "ConfigChanges does not exist in the current context".
    Any ideas?

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    You have to resolve the namespace...

    using Android.Content.PM;

  • DavidPybusDavidPybus AUMember ✭✭

    Thanks for your help - it works perfectly.

    Just FYI it (probably predictably) fails if you are using NavigationPages

  • AlanTonissonAlanTonisson AUMember ✭✭

    I'm having the same problem.
    My app crashes with a null pointer exception in SetPage, when I pass in a NavigationPage.

    Can I create a NavigationPage using a theme without an ActionBar?

  • CheesebaronCheesebaron DKInsider, University mod

    What if you at just one page don't want to show the ActionBar, or maybe show a contextual ActionBar what do you do then?

  • AllisterAllister USMember ✭✭

    for anyone else who ends up here while waiting for title/actionbarless themes to be supported in xamarin.forms, at present the only way I've found to not have an action bar is to set its size to zero.
    0dp in the custom theme example above.
    which feels nasty to me.

  • AnthonyJanssensAnthonyJanssens BEUniversity ✭✭

    @Allister do you need to restore the height of the actionbar afterwards in your app? We are trying to implement a splash screen which needs to be fullscreen (no actionbar) and then show the actionbar once the MainPage has been loaded. Any suggestions?

    It seems we cannot change the height of the actionbar programatically. We can't seem to use the Hide() method of the actionbar either.

  • mkalex777mkalex777 USMember

    I hided acion bar with non-standard theme by calling hide after SetPage. In that way NullReferenceEzception will not appears

  • AllisterAllister USMember ✭✭

    hey @AnthonyJanssens‌, my first impulse would be to have one theme for the splash screen and another for the views you want actionbars on, though I haven't tried that to see if its viable. The app we were doing didn't use a title bar so we weren't trying to turn it back on.
    Good luck.

  • AllisterAllister USMember ✭✭

    The Couchbase Connect 2014 app (https://github.com/FireflyLogic/couchbase-connect-14) is probably a good example of that too (for those who want more code to look at). The default theme is set in the android manifest and a splash theme is specified in the splashscreen.cs file much like Anthonys example, though using windowNoTitle as true rather than actionBarSize as 0dp. I'd forgotten about that example when I replied last time.

  • xeoxeo NZMember
    edited January 2015

    I cannot make it work with Xamarin forms 1.30.
    If I set the size to 0dp nothing happen.
    If instead I use
    item name="android:windowNoTitle">true</item
    the app crashes with reference not set exception:

    [mono] Unhandled Exception:

    [mono] System.NullReferenceException: Object reference not set to an instance of an object
    [mono] at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarHomeAsUp (Android.App.ActionBar actionBar) [0x00000] in :0
    [mono] at Xamarin.Forms.Platform.Android.Platform.HideActionBar () [0x00000] in :0
    [mono] at Xamarin.Forms.Platform.Android.Platform.UpdateActionBar () [0x00000] in :0
    [mono] at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00000] in :0

    this is because I believe xamarin forms is trying to access the action bar which I've removed.

    Any hint on how to make the app fullscreen? @JamesMontemagno @Allister‌ both your solutions don't work on my side.

    thank you.

  • AllisterAllister USMember ✭✭

    @xeo, with a new version of xamarin.forms, all bets are off :-) I haven't tried doing this with 1.3 so apologies that I can't help on this one.

  • xeoxeo NZMember

    @Allister‌ thanks anyway. If in future you will update to 1.3 and it will work let me know.

  • AllisterAllister USMember ✭✭

    @xeo, <item name="android:actionBarSize">0dp</item> works for me.
    I've just run this with a basic xamarin.forms app using 1.3.0.6292, my theme is:
    <?xml version="1.0" encoding="UTF-8" ?> <resources> <style name="CustomTheme" parent="@android:Theme.Holo.Light"> <item name="android:windowFullscreen">true</item> <item name="android:actionBarSize">0dp</item> </style> </resources>
    and my manifest includes:
    <application android:label="AppName" android:icon="@drawable/Icon" android:theme="@style/CustomTheme"></application>

    the title bar isn't visible on normal content pages at least, I haven't gone further.

  • xeoxeo NZMember

    @Allister‌ thank you. I've just realized that my issue was because of my android device which is not a standard android, the status bar is actually the navigation bar, that's why it wasn't working!
    Thank you again!

  • jzeferinojzeferino USUniversity ✭✭

    You can do this in you PAGE constructor to remove the actionbar (android) / navigationbar(ios):

    NavigationPage.SetHasNavigationBar (this, false);

  • ReinhardSualReinhardSual USMember

    It does not work for Android Master Detail Page!

  • Billy12ShovelsBilly12Shovels USUniversity ✭✭✭
    edited July 2015

    I've been trying to find out a way to hide the ActionBar. In the MainActivity.cs in the OnCreate method you can go like this:

    ActionBar.Hide();

    But that only hides it until you switch detail pages. So I used Xamarin.Forms messaging center to hide it every time I switch details:

    MessagingCenter.Subscribe<masterPage, bool>(this, "HideActionBar", (sender, e) => { ActionBar.Hide(); });

    But the animation is ugly. It shows the ActionBar for a brief moment during each detail switch.

  • ReinhardSualReinhardSual USMember

    @Cody , how can you access the ActionBar.Hide() from PCL?
    Thru Interface?

  • Billy12ShovelsBilly12Shovels USUniversity ✭✭✭

    @ReinhardSual If you call MessagingCenter.Subscribe and pass in the correct class, you can use the Messaging Center to get calls from the PCL to the Android Project. Use it like they are in the same Project. It works for me.

    So in my Android app I have MessagingCenter.Subscribe method, and in the PCL class that calls the method I have MessagingCenter.Send

  • ReinhardSualReinhardSual USMember

    Awesome! It works for me.....

    Thanks a lot @CodyRousseau

  • zachwegzachweg USMember
    edited July 2015

    My problem
    Using X.F 1.4.3.6376 the actionbar is visible on a MasterDetailPage when a NavigationPage is the App's MainPage even when calling NavigationPage.SetHasNavigationBar(this, false); in the MasterDetailPage ctor.

    What did and didn't work for me based on all the suggestions above

    • Didn't work - Calling ActionBar.Hide() from my MainActivity's OnCreate method or when injected into the PCL. It threw an exception instead when setting the MainPage

    • Didn't work - Using a custom theme with item android:windowNoTitle set to true and/or with item android:windowFullscreen set to true. It threw an exception instead when setting the MainPage

    • Worked!! - Using a custom theme with item android:actionBarSize set to 0dp hid the actionbar from appearing on the MasterDetail page's master and detail and it stayed hidden when toggling between the two

  • global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);//Oculta la barra

  • DimaMovchanDimaMovchan USMember ✭✭
    edited November 2015

    Thank you @AndresCRGrecia21
    It did the work!

  • taylanduztaylanduz USMember
    edited March 2016

    when application start its not working
    a page with action bar shows up for a few seconds before your mainpage
    @Allister solution is working on both scenerios

  • SivamuralidharSivamuralidhar USMember ✭✭

    How to do this in AppDelegate for ios in xamarin.forms??
    i want to hide the navigationbar in app level while using this chunk of code
    global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);
    it worked it android but in pages i was using this to hide
    protected override void OnAppearing ()
    {
    base.OnAppearing ();
    NavigationPage.SetHasNavigationBar (this, false);
    }
    it is hiding the navigation bar when user enters to the page,i want to hide it before the user enters into page.

  • Ilker55Ilker55 USMember

    For me it worked using actionBarSize=0dp in de theme xml file.
    But when I open a modal the actionbar comes up for like half a second and then disappears.
    Any idea why?

  • keerthanabalakeerthanabala USMember ✭✭

    After hiding the action bar ans status bar in android app .. guys can you please tell me, how can i open the master page using the button ...from the detail page???

  • SureshVMCSureshVMC INMember

    How to permanently remove the actionbar from WebView control in Xamarin android app

  • SureshVMCSureshVMC INMember

    None of the above solution is working for me as I use only webview control in my android app where I want to permanently remove ActionBar.

  • SureshVMCSureshVMC INMember

    How to permanently remove actionbar or atleast share icon from the below code. Kindly help me.
    public class MainActivity : Activity
    {

        WebView web_view;
    
        protected override void OnCreate(Bundle bundle)
        {
            var TokenVal = "NA";
            base.OnCreate(bundle);
    
    
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
    

    web_view = FindViewById(Resource.Id.webview);
    web_view.Settings.JavaScriptEnabled = true;
    web_view.SetWebViewClient(new WebViewClientCls());
    web_view.LoadUrl("https://XXXXX/yyyy.aspx");
    }
    }

  • LucioMSPLucioMSP MXUniversity ✭✭✭

    Someone have the answer? I really want hide the backbutton and show the hamburguer button.

    http://forums.xamarin.com/discussion/73621/backbutton-appears-instead-of-hamburguer-button/p1?new=1

    Regards!!

  • it keeps crashing with an nullreference at LoadApplication(new LCDM2017.App()). After hours of trying, for me the trick was:

    protected override void OnCreate (Bundle bundle)
    {
    base.OnCreate(bundle);

    //hides the title bar in xamarin forms
    global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);
    
    //hide statusbar
    Window.AddFlags(WindowManagerFlags.Fullscreen);
    
    
    global::Xamarin.Forms.Forms.Init(this, bundle);
    LoadApplication(new LCDM2017.App());
    

    }

  • If you just want to hide the status bar just use this line.
    this.Window.AddFlags(WindowManagerFlags.Fullscreen);

Sign In or Register to comment.