Beispiel #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            adapter = new TabsAdapter(this, SupportFragmentManager);
            pager   = FindViewById <ViewPager>(Resource.Id.viewpager);
            var tabs = FindViewById <TabLayout>(Resource.Id.tabs);

            pager.Adapter = adapter;
            tabs.SetupWithViewPager(pager);
            pager.OffscreenPageLimit = 3;

            pager.PageSelected += (sender, args) =>
            {
                var fragment = adapter.InstantiateItem(pager, args.Position) as IFragmentVisible;

                fragment?.BecameVisible();
            };

            Toolbar.MenuItemClick += (sender, e) =>
            {
                switch (e.Item.ItemId)
                {
                case Resource.Id.menu_edit:
                {
                    var intent = new Intent(this, typeof(AddItemActivity));
                    StartActivity(intent);
                    break;
                }

                case Resource.Id.menu_settings:
                {
                    if (!isFormsInitialized)
                    {
                        global::Xamarin.Forms.Forms.Init(this, null);
                        isFormsInitialized = true;
                    }

                    var settings = new SettingsView().CreateFragment(this);

                    break;
                }
                }
            };

            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            _adapter = new TabsAdapter(this, SupportFragmentManager);
            _pager   = FindViewById <ViewPager>(Resource.Id.viewpager);
            var tabs = FindViewById <TabLayout>(Resource.Id.tabs);

            _pager.Adapter = _adapter;
            tabs.SetupWithViewPager(_pager);
            _pager.OffscreenPageLimit = 3;

            _pager.PageSelected += (sender, args) =>
            {
                var fragment = _adapter.InstantiateItem(_pager, args.Position) as IFragmentVisible;

                fragment?.BecameVisible();
            };

            Toolbar.MenuItemClick += ToolbarOnMenuItemClick;

            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);
        }