I am trying to change back arrow image in navigation page. For this in android app i created navigation page renderer and then using method toolbar.SetNavigationIcon and its not working, but when i use toolbar.SetLogo its working fine.
protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
{
base.OnElementChanged(e);
toolbar.SetNavigationIcon(Resource.Drawable.arrow);
toolbar.SetLogo(Resource.Drawable.arrow);
}
public override void OnViewAdded(Android.Views.View child)
{
base.OnViewAdded(child);
if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar))
{
toolbar = (Android.Support.V7.Widget.Toolbar)child;
toolbar.ChildViewAdded += Toolbar_ChildViewAdded;
}
}
I also tried add image to app:navigationIcon in toolbar.axml, and it shows great in designer my arrow
But, when i starting my app i have the same standart arrow icon enter image description here
I solved this the next way: In my MainActivity i am added static toolbar property and identified it in OnCreateOptionsMenu
Then in PageRenderer:
But!! From 2 ways i have bad effect with redrawing
Usage:
If your
MainActivity
isFormsApplicationActivity
, you could refer to this example :https://github.com/jessejiang0214/ChangeBackIconInXF/tree/master/Droid
If your
MainActivity
type isFormsAppCompatActivity
, you could custom aPageRenderer
and change theToolbar
'sNavigationIcon
.For example :
Usage :
Effect.
Update :
When you use
Navigation.PushAsync()
method navigate to another page, the system will automatically update theToolbar
's icon, you could find in the source code :Solution :
So we have no choice but to custom a
NavigationPageRenderer
, override theOnPushAsync
method to set theToolbar
's icon.The
CustomNavigationPage
are defined inPCL
:Usage :