NavigationPage.SetTitleIcon - works on iOS but not Android

Hello,
I added the following..

NavigationPage.SetTitleIcon(this, "LogoLocales.png");

Looks like it should work fine, but only works on iOS not Android.

Any ideas?

Tagged:

Best Answer

  • SpinteractiveSpinteractive ✭✭ US ✭✭
    edited February 2017 Accepted Answer

    Add

    ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/LogoLocales"
    android:layout_gravity="center" /

    to the toolbar.axml

Answers

  • SpinteractiveSpinteractive ✭✭ USMember ✭✭
    edited February 2017 Accepted Answer

    Add

    ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/LogoLocales"
    android:layout_gravity="center" /

    to the toolbar.axml

  • ankur_devankur_dev ✭✭ INMember ✭✭

    Hi @Spinteractive ..

    But this will set the same icon in all the pages. What if we want to set different icons on different pages? How to achieve that?

  • Pierre-ChristopheDusPierre-ChristopheDus ✭✭✭ FRUniversity ✭✭✭

    Hi @ankur_dev
    Did you manage to do that? I also need to display the icon on a single page ...

  • Pierre-ChristopheDusPierre-ChristopheDus ✭✭✭ FRUniversity ✭✭✭
    edited August 2017

    Hi @Spinteractive
    I've seen that you used GrialKit on this project: I use it too for my current project.
    Is it possible to seen the result of your app?
    In add, do you know if there is a way to display the icon on a single page on Android?

  • CarlOrmerod.1629CarlOrmerod.1629 ✭✭ USMember ✭✭
    edited February 2018

    Hi @Pierre-ChristopheDus

    The strategy I used was to have the toolbar addition icon mentioned above hidden, and then on the "OnAppearing" of the Xamarin.Forms page, to call a method using a dependency service to make the icon visible in the toolbar.
    If you are pushing a new page, before you push to a new page make sure you hide it.
    (Note: the delay is there for back navigation animation)

    e.g.
    protected async override void OnAppearing()
    {

            base.OnAppearing();
    
    
            if (Device.RuntimePlatform == Device.Android)
            {
                await Task.Delay(300);
                DependencyService.Get<INavigationIconVisibility>().Visible(true);
            }
    

    }

    Android code:

    public class NavigationIconVisibilityImplementation : INavigationIconVisibility
    {

        public void Visible(bool visible)
        {
            var activity = Forms.Context as AppCompatActivity;
            var iconTitleImageView = (ImageView)activity.FindViewById(Resource.Id.toolbar_icontitle);
            if (iconTitleImageView != null)
            {
                if(visible)
                    iconTitleImageView.Visibility = ViewStates.Visible;
                else
                    iconTitleImageView.Visibility = ViewStates.Invisible;
            }
        }
    }
    
Sign In or Register to comment.