Hi Guys,
I have been working on Xamarin Forms and I wanted to set an image as background image into navigation bar but I couldn't I have tried a lot but no luck at that time.
Then something hit in my mind and I tried and that works pretty charms! You just need to make a renderer and there a single method will help you.
Have a look
Android
[assembly: ExportRenderer(typeof(ContentPage), typeof(ContentPageRenderer))]
namespace MyApp.Renderers
{
public class ContentPageRenderer : PageRenderer
{
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
var actionBar = ((Activity)Context).ActionBar;
actionBar.SetBackgroundDrawable(Resources.GetDrawable(Resource.Drawable.YourImageInDrawable));
}
}
}
iOS
[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(BlueNavigationRenderer))]
namespace MobileCRM.iOS.Renderers
{
public class BlueNavigationRenderer : NavigationRenderer
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.NavigationBar.BarTintColor = UIColor.FromPatternImage(UIImage.FromFile("topbar_bg@2x.png"));
}
}
}
Here we go!! This post will help you to customize you navigation bar.