How To Access Tap Or Click Of An Toolbar Image In Android Xamarin Forms
I have placed an image inside toolbar like in the below code. I did this to have an toolbar icon on the left side.
Solution 1:
I am looking for a way to place toolbaritem on the left side of the toolbar in xamarin forms application
You could refer to my answer : Xamarin.forms toolbar Android .
Place ToolbarItem
on the left side of the toolbar in Xamarin.Forms
, put this code in yourPage.xaml
:
<ContentPage.ToolbarItems>
<ToolbarItem Text="Share" Activated="EditClicked_Share"Order="Primary" Priority="0" />
<ToolbarItem Text="Create" Activated="EditClicked_Create"Order="Primary" Priority="1" />
<ToolbarItem Text="Save" Activated="EditClicked_Save"Order="Primary" Priority="2" Icon="ic_action_content_save.png" />
</ContentPage.ToolbarItems>
I need to access the tap or click of the image
In yourPage.cs
:
privatevoidEditClicked_Save(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Picture Clicked");
}
Update :
This isn't currently supported in Forms, you could write a Custom Renderer that overrides the base Android Toolbar
renderer.
Herer is a simple solution, create a picture which color is same with the Toolbar
, in my project, my picture is blue.png
:
Place it left side of the Toolbar
, add some blank ToolbarItem
between the picture and your ToolbarItem
to adjust the space.
<ContentPage.ToolbarItems><ToolbarItemActivated="EditClicked_Save"Order="Primary"Priority="0"Icon="ic_action_content_save"/><ToolbarItemOrder="Primary"Priority="0" /><ToolbarItemOrder="Primary"Priority="0" /><ToolbarItemOrder="Primary"Priority="0" /><ToolbarItemOrder="Primary"Priority="0" /><ToolbarItemOrder="Primary"Priority="1"Icon="blue"/></ContentPage.ToolbarItems>
Effect :
Post a Comment for "How To Access Tap Or Click Of An Toolbar Image In Android Xamarin Forms"