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

How to assign an icon to the Navigation Bar for a single page on Android

$
0
0

Hello,

I try to use an icon instead of the title on the main page of my Xamarin.Forms app.

I've read a lot of related topics, but I didn't found any solution:
navigationpage-settitleicon
navigationpage-settitleicon-works-on-ios-but-not-android
toolbar-title-set-center-align
xamarin-forms-custom-toolbar-android

On iOS this is done easily by adding this on my first page:
NavigationPage.SetTitleIcon(this, "navbar_logo.png");

On Android, I've added this on Toolbar.axml:
<ImageView android:src="@drawable/navbar_adp_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" />

This works, but the icon is now visible on each page on Android.

I've tried to use a renderer to hide the icon when I navigate to another page. For this I would like to use the override OnViewAdded() method:

public class CustomNavigationPageRenderer : NavigationPageRenderer { public override void OnViewAdded(Android.Views.View child) { ... } }

But I can't cast the child into Xamarin.Forms.Platform.Android.PageContainer, cause this object is "internal".

So I don't see how I could achieve this...
Would you have any suggestion?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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