Xamarin shapes the position of toolbar elements for android

I want the ToolbarItem Menu1 on the left side, but at this point both are on the right side. How can i fix this?

<?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Dharma.LoginPage"> <ContentPage.ToolbarItems> <ToolbarItem Name="Menu1" Order="Primary" Priority="0" /> <ToolbarItem Name="Menu2" Order="Primary" Priority="1" /> </ContentPage.ToolbarItems> <ContentPage.Content> <StackLayout Padding="30"> <Label Text="Login Page" FontSize="20" /> </StackLayout> </ContentPage.Content> </ContentPage> 
+5
source share
3 answers

As already mentioned, this can only be done using a custom renderer for your page . Then you need to move the whole logic of creating the menu item, since the Xamarin built into the ToolbarItem will cause all kinds of problems with your user logic. You can refer to this answer for more details on how to move objects to the left - it is somehow similar, so it may be a better idea to just live with them on the right.

+1
source

This is not a feasible solution. I know, but so far I have tried it. just add empty toolbars between menu1 and menu2 to create a space between them.

Thus, it will be installed on the left and right, respectively

 <ContentPage.ToolbarItems> <ToolbarItem Name="Menu1" Order="Primary" Priority="0" /> <ToolbarItem Name="" Order="Primary" Priority="0" /> <ToolbarItem Name="" Order="Primary" Priority="0" /> <ToolbarItem Name="" Order="Primary" Priority="0" /> <ToolbarItem Name="" Order="Primary" Priority="0" /> <ToolbarItem Name="Menu2" Order="Primary" Priority="1" /> 

+8
source

This is currently not supported on Forms. To get around this, you can write a Custom Renderer that overrides the basic rendering of the Android toolbar.

+3
source

Source: https://habr.com/ru/post/1247427/


All Articles