How to find toolbar by using resources Id for tabbedpage in Xamarin.Forms

S GAIKWAD 226 Reputation points

My page is a TabbedPage on this page. Uses a badge inside the TabbedPage.toolbar item.
I was referred to the link.

<ToolbarItem Name="MenuItem1" Order="Primary" IconImageSource="cart.xml" Text="Item 1" Priority="0" />

var toolbar = CrossCurrentActivity.Current.Activity.FindViewById(Resource.Id.toolbar) as Android.Support.V7.Widget.Toolbar;

toolbar always get null .

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,258 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,956 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,931 Reputation points


    Welcome to our Microsoft Q&A platform!

    To get the Toolbar, the application should use the navigation bar (toolbar) which means the MainPage should be a NavigationPage like below.

       public partial class App : Application  
           public App()  
               MainPage = new NavigationPage(new MainPage());  

    But you used a TabbedPage as the application template, so the toolbar will be null. What do you want to do with the toolbar?

    Best Regards,

    Jarvan Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments