Janine Alexander
Janine Alexander

Reputation: 161

Display of screen is pushed down xamarin.forms android

Weirdly my display of screen is pushed down for only the MainPage thereafter display fits the screen as it should. I've tried deleting the page and re-adding it but that didn't work either. Does anyone know what could be causing this and how to fix it?

Here's what it looks like: The black space at the top should not be there Image

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="LoyaltyWorx.Views.MainPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:LoyaltyWorx.Views.Converters"
    xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
    prism:ViewModelLocator.AutowireViewModel="True"
    >
    <ContentPage.Resources>
        <ResourceDictionary>
            <local:InvertBooleanConverter x:Key="InvertBooleanConverter" />
        </ResourceDictionary>
    </ContentPage.Resources>
    <Grid>
        <Image Source="bk3.jpg" Aspect="AspectFill"/>
        <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
        <StackLayout Orientation="Horizontal" VerticalOptions="Start">
            <!-- top controls -->
        </StackLayout>
        <StackLayout VerticalOptions="CenterAndExpand">
            <!-- middle controls -->
            <BoxView HeightRequest="430"></BoxView>
            <Button Text="Continue with Facebook" x:Name="LoginBtn" BackgroundColor="#4867aa" TextColor="White" FontFamily="Klavika" HorizontalOptions="CenterAndExpand" Clicked="LoginBtn_Clicked" />
            <Button Text="Continue with Google  " Command="{Binding GoogleLoginCommand}" BackgroundColor="#d34836" TextColor="White" FontFamily="Klavika" HorizontalOptions="CenterAndExpand"/>
        </StackLayout>
        <StackLayout Orientation="Horizontal" VerticalOptions="End" HorizontalOptions="Center">
            <!-- bottom controls -->
            <Frame OutlineColor="White" HorizontalOptions="StartAndExpand">
                <StackLayout Orientation="Horizontal" VerticalOptions="End" HorizontalOptions="Center">
                    <!-- bottom controls -->
                    <StackLayout Grid.Row="1" Orientation="Horizontal" Spacing="0">
                        <Label  
                               Text="Terms and conditions"
                              FontSize="13"
                            TextColor="#71757a"
                            FontAttributes="Bold"
                            x:Name="LblTerms"/>
                        <Label  
                            Text=" and"
                            FontSize="13"
                            TextColor="#71757a"
                            />

                        <Label  
                               Text=" privacy policy"
                            FontSize="13"
                            TextColor="#71757a"
                            FontAttributes="Bold"
                            x:Name="LblPrivacy"/>
                    </StackLayout>

                </StackLayout>
            </Frame>
        </StackLayout>
    </StackLayout>
    </Grid>
</ContentPage>

App.cs

public partial class App : PrismApplication
    {

        public App(IPlatformInitializer initializer = null) : base(initializer) { }


        protected override void OnInitialized()
        { 
            InitializeComponent();
            SetMainPage();
            NavigationService.NavigateAsync("NavigationPage/MainPage?title=Hello%20from%20Xamarin.Forms");
        }

        protected override void RegisterTypes()
        {
            Container.RegisterTypeForNavigation<NavigationPage>();
            Container.RegisterTypeForNavigation<MainPage>();
        }

        private void SetMainPage()
        {
            if (!string.IsNullOrEmpty(Helpers.Settings.Usertoken))
            {
                Application.Current.MainPage = (new Profile());
            }
            else
            {
                MainPage = new NavigationPage(new MainPage())
                { BarBackgroundColor = Color.FromHex("#393b3d") };

            }
        }

        public async static Task NavigateToSMS()
        {
            await Application.Current.MainPage.Navigation.PushAsync(new SMS());
        }

        public static void NavigateToProfile()
        {
            Application.Current.MainPage = (new InvalidLogin());
        }
        public static void NavigateToVerified()
        {
            Application.Current.MainPage = (new Profile());
        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }

Upvotes: 0

Views: 627

Answers (1)

Nick Peppers
Nick Peppers

Reputation: 3251

You have your MainPage wrapped in a NavigationPage that by default shows the NavigationBar. You can turn it off in your cs code or in your MainPage.xaml

cs

var mainPage = new MainPage();
MainPage = new NavigationPage(mainPage);
NavigationPage.SetHasNavigationBar(mainPage, false);

xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="LoyaltyWorx.Views.MainPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:LoyaltyWorx.Views.Converters"
    xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
    prism:ViewModelLocator.AutowireViewModel="True"
    NavigationPage.HasNavigationBar="False">

Upvotes: 2

Related Questions