简体   繁体   中英

How to set Title in center of navigation bar Xamarin.forms

How to set Title into center of Navigation Bar. Can we set without custom render. I have used

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Toolbar Title" android:layout_gravity="center" android:id="@+id/toolbar_title" /> 

But Its not working

Here's one hackish way with the new NavigationPage.TitleView - Android seems to reserve a portion of the title view for the back button by default, so you can just set a margin that offsets the left hand reserved area:

<ContentPage>
    <NavigationPage.TitleView>
        <StackLayout>
            <Label Text="More Text" TextColor="White" HorizontalTextAlignment="Center" FontSize="20" Margin="0, 0, 75, 0" />
        </StackLayout>
    </NavigationPage.TitleView>
        ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM