tl;dr
When I programmatically set the icon on my Toolbar and then rotate the device, the icon is gone.
Earlier I asked a question about how to gain access to the new AppCompat Toolbar, and while I was able to answer my own question, I did run into a snag with regards to what happens when the device is rotate.
Essentially what I'm trying to do is declare the "Icon" property on the Page and then use it as the Toolbar.Icon within a custom renderer. The code below works until the device is rotated, then the icon is gone forever
public class ExtendedPageRenderer : PageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
SetToolbarIcon();
}
protected override void OnConfigurationChanged(Configuration newConfig)
{
base.OnConfigurationChanged(newConfig);
SetToolbarIcon();
}
private void SetToolbarIcon()
{
if (Element == null || Element.Icon == null)
{
return;
}
// add the page icon to the Navigation Bar.
var iconId = ResourceManager.GetDrawableByName(Element.Icon.File);
var toolbar = MainActivity.RootFindViewById<Toolbar>(Resource.Id.toolbar);
if (toolbar != null)
{
toolbar.SetLogo(iconId);
}
}
}
I just don't understand the inner workings of the MainActivity.SupportActionBar