Forum Xamarin.Android

Navigation Drawer with tab in main page android xamarin

I make an app with Navigation Drawer. I want to add a tab in main page but when I run the app, i have an error in
System.NullReferenceException: Object reference not set to an instance of an object.
in
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;

my code is :
`namespace NavigationDrawerLayout
{
[Activity(Label = "NavigationDrawerLayout", Theme = "@style/Theme.DesignDemo", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : AppCompatActivity
{

    DrawerLayout drawerLayout;
    NavigationView navigationView;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);
        ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;


        // Add the tabs to Action Bar  
        AddTab("Tab One");
        AddTab("Tab Two");
        AddTab("Tab Three");
        drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);


        // Create ActionBarDrawerToggle button and add it to the toolbar
        var toolbar = FindViewById<V7Toolbar>(Resource.Id.toolbar);
        SetSupportActionBar(toolbar);


        var drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.drawer_open, Resource.String.drawer_close);
        drawerLayout.SetDrawerListener(drawerToggle);
        drawerToggle.SyncState();

        navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
        setupDrawerContent(navigationView);



    }
    private void AddTab(string tabText)
    {
        Android.App.ActionBar.Tab tab = ActionBar.NewTab();
        tab.SetText(tabText);
        tab.TabSelected += OnTabSelected;
        ActionBar.AddTab(tab);
    }
    private void OnTabSelected(object sender, Android.App.ActionBar.TabEventArgs args)
    {
        var CurrentTab = (Android.App.ActionBar.Tab)sender;

        if (CurrentTab.Position == 0)
        {

        }

        else
        {

        }
    }
    void setupDrawerContent(NavigationView navigationView)
    {
        navigationView.NavigationItemSelected += (sender, e) => {
            e.MenuItem.SetChecked(true);
            drawerLayout.CloseDrawers();
        };
    }

    public override bool OnCreateOptionsMenu(IMenu menu)
    {

        navigationView.InflateMenu(Resource.Menu.nav_menu);
        return true;

    }

    }

}`

Answers

Sign In or Register to comment.