is the Xamarin forms navigation a Toolbar or an ActionBar?
It is a Toolbar and not an ActionBar
Android.Support.V7.Widget.Toolbar
You can set the color via the ToolBar.NavigationIcon.SetColorFilter(...), but you have to find it first as Xamarin is not applying it via SetSupportActionBar
...
Red backbutton PlatformEffect
example:
public class RedBackButtonColorNameEffect : PlatformEffect
{
protected override void OnAttached()
{
void ViewGroups(ViewGroup viewGroup)
{
for (int i = 0; i < viewGroup.ChildCount; i++)
{
Android.Views.View v = viewGroup.GetChildAt(i);
switch (v)
{
case Toolbar tb:
tb.NavigationIcon?.SetColorFilter(viewGroup.Resources.GetColor(Android.Resource.Color.HoloRedDark), PorterDuff.Mode.SrcAtop);
return;
case ViewGroup vg:
ViewGroups(vg);
break;
}
}
}
var rootView = (Control.Context as AppCompatActivity).FindViewById(Android.Resource.Id.Content).RootView as ViewGroup;
ViewGroups(rootView);
}
protected override void OnDetached()
{
}
}
Usage:
someControl.Effects.Add(Effect.Resolve("Effects.RedBackButtonColorNameEffect"));
(remember set your ResolutionGroupName
& ExportEffect
attributes...)
Note: Xamarin does not apply a value for the Control
instance within a PlatformEffect if you attach the effect at the page level or a container level and thus this will not work. You could store the Activity context somewhere (static var) from the MainActivity in order to workaround that issue and thus have the proper Context
to search within, your choice..
Note!: PlatformEffects are whack in so many ways, especially since they never get garage collected and thus are a memory leak, they are nice for a quick example/prototype, but use a custom renderer for production code).