NavigationRenderer on Android?

I need to customize the appearance of the navigation bar that is part of the NavigationPage. In short, I need a background image for the navigation bar and a horizontal rule along the bottom edge of the navigation bar. I was able to get this working iOS just fine:

`
public class CustomNavigationPageRenderer : NavigationRenderer
{
public CustomNavigationPageRenderer ()
{

    }

    public override void ViewDidLoad() {
        base.ViewDidLoad ();
        UIImage shadow = UIImage.FromFile ("navbarShadowImg.png");
        this.NavigationBar.ShadowImage = shadow;
        UIImage background = UIImage.FromFile (GetPathToBackgroundImage());
        this.NavigationBar.SetBackgroundImage (background, UIBarMetrics.Default);

        UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes() {
            TextColor = UIColor.White,

        }); 
    }

    private static string GetPathToBackgroundImage() {
        string path = "navbarBackground.png";

        if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) {

            if (UIScreen.MainScreen.Bounds.Width >= 750)
                path = "[email protected]\t";
        }

        return path;
    }
}`

When I started on the Android implementation I was having a hard time figuring out what I need to customize. I need to support API 18 and above and was thinking that I needed to get the ActionBar instance from the activity. Here's what I have so far:

`public class CustomNavigationPageRenderer : NavigationRenderer
{
public CustomNavigationPageRenderer ()
{
}

    protected override void OnElementChanged (ElementChangedEventArgs<NavigationPage> e)
    {
        base.OnElementChanged (e);

        var activity = this.Context as Activity;
        activity.ActionBar.Subtitle = "Testing...";
        activity.ActionBar.SetBackgroundDrawable (activity.Resources.GetDrawable (Resource.Drawable.navbarBackground));
    }
}`

The text ("Testing...") shows up on the far left of the navigation bar and the image doesn't show up at all. Any tips or pointers on what I should be looking at? Do I need to create a "CustomView"? Worried that if I make a custom view the buttons I have defined through XamForms won't function properly. Any help or advice would be appreciated!

Sign In or Register to comment.