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.

Navigation Title not centering on Android

Conor.MurphyConor.Murphy GBMember ✭✭
edited October 2019 in Xamarin.Forms

I’ve set the navigation title in my Xamarin forms application as below:

    <NavigationPage.TitleView>
        <Grid>
            <Label Text="Settings" Style="{StaticResource NavTitle}"/>
            <Button Text="&#xf060;" Style="{StaticResource LeftNavButton}" Clicked="BackButtonClicked"/>
        </Grid>
    </NavigationPage.TitleView>

The Label has been centered, on iOS the positioning is fine but on Android it is shifted over to the right. I've set the navigation back button to be hidden with NavigationPage.SetHasBackButton(this, false) but it seems to still be pushing it over, does anybody have any insight to why it's shifted over on Android and not iOS?

Images attached, Thanks in advance!

Below is the styles for reference:

         <Style x:Key="LeftNavButton" TargetType="Button">
            <Setter Property="BackgroundColor" Value="Transparent"/>
            <Setter Property="TextColor" Value="White"/>
            <Setter Property="HeightRequest" Value="20"/>
            <Setter Property="FontSize" Value="20"/>
            <Setter Property="FontFamily" Value="{StaticResource FontAwesomeSolid}"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="HorizontalOptions" Value="Start"/>
            <Setter Property="WidthRequest" Value="30"/>
            <Setter Property="Margin" Value="{StaticResource LeftButtonMargin}"/>
        </Style>

        <Style x:Key="NavTitle" TargetType="Label">
            <Setter Property="FontAttributes" Value="Bold"/>
            <Setter Property="TextColor" Value="White"/>
            <Setter Property="HeightRequest" Value="20"/>
            <Setter Property="FontSize" Value="17"/>
            <Setter Property="VerticalTextAlignment" Value="Center"/>
            <Setter Property="HorizontalTextAlignment" Value="Center"/>
            <Setter Property="HorizontalOptions" Value="CenterAndExpand"/>
            <Setter Property="VerticalOptions" Value="CenterAndExpand"/>
        </Style>

Best Answer

Answers

  • Conor.MurphyConor.Murphy GBMember ✭✭

    Images attached

  • ssamixssamix Member ✭✭✭

    it is not working , something wrong?

  • CytophCytoph Member ✭✭

    @ssamix said:
    it is not working , something wrong?

    Same problem for me. This workaround does not seem to work anymore. Ideas anyone?

Sign In or Register to comment.