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

S GAIKWAD 206 Reputation points
2021-05-06T11:00:30.497+00:00

My page is a TabbedPage on this page. Uses a badge inside the TabbedPage.toolbar item.
I was referred to the https://github.com/CrossGeeks/ToolbarItemBadgeSample link.

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

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

toolbar always get null .

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,811 questions
C#
C#
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.
6,967 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,846 Reputation points
    2021-05-06T12:57:32.02+00:00

    Hello,​

    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()  
           {  
               InitializeComponent();  
         
               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.

    No comments