Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

NavigationBar Background Image Renderer Android

$
0
0

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!! :D This post will help you to customize you navigation bar.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>