Eric Ouellet
Eric Ouellet

Reputation: 11754

How to make a Xamarin app fullscreen (all screen)

I develop with Xamarin 4.5 and I'm not able to find how to put my application to cover the entire screen (full screen).

For Android and for iOS.

Note: I do not want only an image or a video to cover the entire screen, it should be all the application that should cover the entire screen.

Update 2020-04-29 I found half of the solution, only the Android part (inlcluded in my answer with help of FabriBertani for status bar). I tested it and it works fine. Now I have to find a solution for iPhone (or at least, find a way to test on an iPhone).

Upvotes: 3

Views: 12486

Answers (2)

Eric Ouellet
Eric Ouellet

Reputation: 11754

This is half of the solution. For Android:

In Android Project. Into MainActivity.OnCreate, add:

this.Window.AddFlags(WindowManagerFlags.Fullscreen); // Hide StatusBar, from FabriBertani

MessagingCenter.Subscribe<Object>(this, "HideOsNavigationBar", (sender) => 
{
  int uiOptions = (int)Window.DecorView.SystemUiVisibility;
  uiOptions |= (int)SystemUiFlags.HideNavigation;
  Window.DecorView.SystemUiVisibility = (StatusBarVisibility) SystemUiFlags.HideNavigation;
});

In Shared project. Into MainPage constructor (I put it after InitializeComponent() but I doubt it is necessary):

MessagingCenter.Send<Object>(this, "HideOsNavigationBar");

Upvotes: 5

FabriBertani
FabriBertani

Reputation: 1636

On Android add this to the OnCreate method of your MainActivity:

this.Window.AddFlags(WindowManagerFlags.Fullscreen);

For iOS add these values to the info.plist file:

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

edit: If you want to remove the toolbar too just add this on your xaml pages:

NavigationPage.HasNavigationBar="False"

Or in the C# code behind

public YourPage()
{
    InitializeComponent();

    NavigationPage.SetHasNavigationBar(this, false);
}

If you want to add this to all your pages, I recommend you to create a base page with this and then use this base page in all your pages.

public class BaseContentPage : ContentPage
{
    public BaseContentPage
    {
        NavigationPage.SetHasNavigationBar(this, false);
    }
}

And use it on the xaml:

<?xml version="1.0" encoding="UTF-8"?>
<local:BaseContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:YourNamespace.Pages"
    x:Class="YourNamespace.Pages.YourPage">
</local:BaseContentPage>

Upvotes: 8

Related Questions