Xamarin forms ToolBar default icon

Does anyone know how to remove or replace the default icon in the toolbar?

I have searched a lot and all i can see is that i can add new tool bar items, that are added to the right of the screen with no other layout options. i wish to have something like picture 2 that i uploaded.

Posts

  • AmerradiAmerradi USMember, University ✭✭
    edited February 2016

    you need to use the icon property in the toolbaritems:

            /* Assuming that the icons are saved in the following directories:
                            iOS: Resources\Icons\MyIcon.png
                          Android: Resources\drawable\MyIcon.png
                          WP: Assets\Icons\MyIcon.png */
    
          string MyIcon = String.Format("{0}{1}.png", Device.OnPlatform("Icons/", "", "Assets/Icons"), "MyIcon.png");
                  this.ToolbarItems.Add (new ToolbarItem () { Icon = MyIcon } );
    
  • devnldevnl NLUniversity ✭✭

    To remove the actual app Icon you can use a custom style, something like:

    <style name="Theme.Main" parent="android:style/Theme.Material.Light.DarkActionBar"> <item name="android:icon">@android:color/transparent</item> </style>

    Which you can then set on your MainActivity:

    [Activity(Label = "My app", Theme = "@style/Theme.Main")] public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity { }

    To get an icon like the one on the right you can use this in the Page.xaml of the page that needs it:

    <ContentPage.ToolbarItems> <ToolbarItem Icon="someicon.png" Command="{Binding SomeCommand}" /> </ContentPage.ToolbarItems>

    The hamburger menu should come with the built in MasterDetailPage which you could use.

  • hey guys,

    I tried your suggestions with varying results, I stumbled upon a nuget package called Scn.TitleBar.Forms that suggests that it covers android, iOS and windows phone although it doesn't seem to work on windows phone me, but I don't mind as their apps don't really come with tool bars. Anyway I found the tool really useful and thought id share it in case someone else came upon the same problem.

    thanks again.

  • PhilipOchuPhilipOchu USBeta, University ✭✭✭

    I would convert your Android App to use the FormsAppCompatActivity - it allows you to style your toolbar pretty much anyway you want because you have access to axml of your toolbar (and also your tabs if using tabs).

    Check out this article that shows you how to set it up.

    https://blog.xamarin.com/material-design-for-your-xamarin-forms-android-apps/

Sign In or Register to comment.