3

I had an issue in removing the extra left space in title view as shown in the image below please see the screenshot here

Ps: I'm using tabbed page and that bar is the navigation title view.

2 Answers2

2

Set the xml below in your Toolbar.xml of Android part.

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp" 

enter image description here

Do not forget to add the namespace of app in your Toolbar.xaml.

xmlns:app="http://schemas.android.com/apk/res-auto"

And check the code below, it need to be added in MainActivity.cs.

ToolbarResource = Resource.Layout.Toolbar;

Usage:

<NavigationPage.TitleView>
    <Label Text="Repositories" />
</NavigationPage.TitleView>

enter image description here

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17
  • thnx a lot u just saved my life( although I lost full 7 hours of searching) – Bahri Mouhib Mar 25 '20 at 14:34
  • Okay, seems to work now. I think it was just necessary to remove all bin and obj folders from PCL and android project. – Christoph Mett Oct 06 '20 at 12:14
  • Dosn't Work for me ... Any Idea why ? Here is my Toolbar.xml : `` – Belight Apr 07 '21 at 11:11
  • 2
    Change `android.support.v7.widget.Toolbar` to `androidx.appcompat.widget.Toolbar`. – Wendy Zang - MSFT Apr 08 '21 at 07:11
  • Indeed !!! Same question [here](https://stackoverflow.com/questions/66990741/how-to-remove-left-space-in-toolbar-and-above-and-under) with a detailled explanation of your proposal. The solution here above was not working for me – Belight Apr 08 '21 at 08:44
0

Another solution without customizing the xml layout is for those who already created a IShellToolbarAppearanceTracker subclassing ShellToolbarAppearanceTracker :

        public override void SetAppearance(Toolbar toolbar, IShellToolbarTracker toolbarTracker, ShellAppearance appearance)
        {
            base.SetAppearance(toolbar, toolbarTracker, appearance);

            toolbar.SetContentInsetsAbsolute(0,0);
        }

The native problem is discussed here:

Toolbar extra left inset/padding

Nick Kovalsky
  • 5,378
  • 2
  • 23
  • 50