NavigationBar Background Image Renderer Android

2»

Posts

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    @ZacariasJunior.1883 I have updated new code snippet for android here by doing this you don't need to add renderer for android.

    Cheers!!
    { rzee }

  • nitudnitud INMember ✭✭

    Hey ....i want to add labels within the header like attached image.....can you help me

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    Hey @nitud

    Sure, You can use Toolbar property SubTitle to achieve this thing.

    var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
    Title = "Profile";  //Activity Property
    toolbar.Subtitle = "Test";
    

    You Can Do It

    Cheers!!
    { rzee }

  • nitudnitud INMember ✭✭

    thank you for your reply ...For this i need to use custom renderer but if i want to solve it at xamarin.forms level then how it can?

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    Hello @nitud
    One Suggestion: Always mention maximum details about your requirements e.g. Platform, Technology etc you didn't mention these things in your question, now it is showing you are using Xamarin Forms :).

    Coming to your point, I will post the solution soon.

    Cheers!!
    { rzee }

  • rzee7rzee7 INUniversity ✭✭✭✭✭
    edited June 8

    Hey @nitud Please find your solution at below:

    • Xamarin Forms Project PCL/Shared Code:

      using Xamarin.Forms;
      
      namespace YourProject.Views
      {
          public partial class MainPage : ContentPage
          {
              public MainPage()
              {
                  InitializeComponent();
                  ClassId = "Your subtitle";
              }
          }
      }
      
    • Xamarin Droid Renderer Code:

      using Android.Widget;
      using Xamarin.Forms;
      using Xamarin.Forms.Platform.Android;
      
      [assembly: ExportRenderer(typeof(ContentPage), typeof(DroidPageRenderer))]
      namespace YourProject.Droid
      {
          public class DroidPageRenderer : PageRenderer
          {
              protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
              {
                  base.OnElementChanged(e);
                  if (e.NewElement != null && Context != null)
                  {
                      var toolbar = (Context as MainActivity).FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
                      if (toolbar == null) return;
                      toolbar.Subtitle = e.NewElement.ClassId;
                      //We are using existing property to set subtitle in renderer, 
                      //Although you can have your own property instead ClassId but you have to create a BasePage.
                  }
              }
          }
      }
      

    Here is your result:
    Got It

    Cheers!!
    { rzee }

  • jmccormickjmccormick USMember ✭✭

    @rzee7 Do you have a working version of this you can share on Github?

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    Hey Guys,

    Here is working Sample:

    Result:

    Cheers!!
    { rzee }

  • DhruvaHeinDhruvaHein USMember ✭✭

    Thanks rzee7! You da man!

  • @rzee7 said:
    Hey Guys,

    Here is working Sample:

    Result:

    Cheers!!
    { rzee }

    It Works, Thanks man.

  • Pierre-ChristopheDusPierre-ChristopheDus FRUniversity ✭✭

    Hello,
    I develop a Xamarin.Forms app and I would like to know is there is a way to apply an image as title for the navigation bar, but only for the main page of the app?
    For the other pages, I would like to use the default navigation bar...

  • ravaliravali INMember
    edited September 12

    @rzee7 android:background="@drawable/bar" is not working for me.can u please help me out of this.

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    @Pierre-ChristopheDus did you get this fixed?

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    @ravali What is an issue with this? You can take a look in the sample.

    Thanks
    { rzee }

  • ravaliravali INMember

    @rzee7 After applying this android:background="@drawable/bar" it is showing perfect in toolbar.designer but when i am trying to deploy on device it is showing default color what is being used "?attr/colorPrimary"

    Thanks
    ravali

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    @ravali Can you post your code here?

    Thanks
    { rzee }

  • ravaliravali INMember

    @rzee7 Thanks.I resolved my issue

2»
Sign In or Register to comment.