Xamarin forms ToolbarItem spacing

Stephen He 21 Reputation points
2020-12-11T18:49:15.927+00:00

I am trying to reduce the spacing between my ToolbarItems on a ContentPage on Android. I have tried the suggested fix from this link https://forums.xamarin.com/discussion/165702/how-do-i-change-the-size-of-an-image-for-a-toolbaritem which is working for iOS, but not for Android. Is there an equivalent to the custom iOS renderer for Android which will have the same effect?47502-app.jpg

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Answer accepted by question author
  1. JarvanZhang 23,971 Reputation points
    2020-12-14T05:31:20.767+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Hi,StephenHe-2089. For this function on Android, you could set style for the ActionButton and consume the style for the theme of MainActivity class. The code of the link you posted could reduce the spacing of the ToolbarItems well. Change the value of the width item properties to adjust the space.

    Here is the screenshot:
    47802-image.png

    Checkt the code:

       <resources>  
         <style name="MainTheme" parent="MainTheme.Base">  
           ...  
           <item name="actionButtonStyle">@style/myActionButtonStyle</item>  
         </style>  
         
         <style name="myActionButtonStyle" parent="Widget.AppCompat.ActionButton">  
           <item name="android:minWidth">35dp</item>  
           <item name="android:maxWidth">35dp</item>  
           <item name="android:width">35dp</item>  
         </style>  
       </resources>  
    

    Or you could use TitleView to display the items on the navigation bar.

       <NavigationPage.TitleView>  
           <!--the items-->  
       </NavigationPage.TitleView>  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.