Beispiel #1
0
        public override Widget build(BuildContext context)
        {
            BottomNavigationBar botNavBar = new BottomNavigationBar(
                items: this._navigationViews
                .Select <NavigationIconView, BottomNavigationBarItem>((NavigationIconView navigationView) =>
                                                                      navigationView.item)
                .ToList(),
                currentIndex: this._currentIndex,
                type: this._type,
                onTap: (int index) =>
            {
                this.setState(() =>
                {
                    this._navigationViews[this._currentIndex].controller.reverse();
                    this._currentIndex = index;
                    this._navigationViews[this._currentIndex].controller.forward();
                });
            }
                );

            return(new Scaffold(
                       appBar: new AppBar(
                           title: new Text("Bottom navigation"),
                           actions: new List <Widget>
            {
                new MaterialDemoDocumentationButton(BottomNavigationDemo.routeName),
                new PopupMenuButton <BottomNavigationBarType>(
                    onSelected: (BottomNavigationBarType value) =>
                {
                    this.setState(() => { this._type = value; });
                },
                    itemBuilder: (BuildContext subContext) => new List <PopupMenuEntry <BottomNavigationBarType> >
                {
                    new PopupMenuItem <BottomNavigationBarType>(
                        value: BottomNavigationBarType.fix,
                        child: new Text("Fixed")
                        ),
                    new PopupMenuItem <BottomNavigationBarType>(
                        value: BottomNavigationBarType.shifting,
                        child: new Text("Shifting")
                        )
                }
                    )
            }
                           ),
                       body: new Center(
                           child: this._buildTransitionsStack()
                           ),
                       bottomNavigationBar: botNavBar
                       ));
        }
        private void handleDirection(CoordinatorLayout parent, V child, ScrollDirection scrollDirection)
        {
            BottomNavigationBar bottomNavigationBar = (BottomNavigationBar)mViewRef.Get();

            if (bottomNavigationBar != null && bottomNavigationBar.AutoHideEnabled)
            {
                if (scrollDirection == ScrollDirection.SCROLL_DIRECTION_DOWN && bottomNavigationBar.Hidden)
                {
                    updateSnackBarPosition(parent, child, getSnackBarInstance(parent, child), -mBottomNavHeight);
                    bottomNavigationBar.show();
                }
                else if (scrollDirection == ScrollDirection.SCROLL_DIRECTION_UP && !bottomNavigationBar.Hidden)
                {
                    updateSnackBarPosition(parent, child, getSnackBarInstance(parent, child), 0);
                    bottomNavigationBar.hide();
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_use_in_fragment);
            _vpHome = FindViewById <ViewPager>(Resource.Id.vp_home);
            _bottomNavigationBar = FindViewById <BottomNavigationBar>(Resource.Id.bottom_navigation_bar);
            _bottomNavigationBar.AddItem(new BottomNavigationItem(Resource.Drawable.ic_favorite, "One"))
            .AddItem(new BottomNavigationItem(Resource.Drawable.ic_gavel, "Two"))
            .AddItem(new BottomNavigationItem(Resource.Drawable.ic_grade, "Three"))
            .AddItem(new BottomNavigationItem(Resource.Drawable.ic_group_work, "Four"))
            .Initialise();

            _bottomNavigationBar.SetTabSelectedListener(new TabSelectedListener(_vpHome));

            _fragmentList.Add(new ImageFragment());
            _fragmentList.Add(new SimpleFragment());
            _fragmentList.Add(new SimpleFragment());
            _fragmentList.Add(new SimpleFragment());

            _vpHome.PageSelected += (s, e) =>
            {
                _bottomNavigationBar.SelectTab(e.Position);
                switch (e.Position)
                {
                case 0:
                    break;

                default:
                    var random = new Random();
                    var color  = (int)(0xff000000 | random.Next(0xffffff));
                    if (_fragmentList[e.Position] is SimpleFragment)
                    {
                        ((SimpleFragment)_fragmentList[e.Position]).SetTvTitleBackgroundColor(color);
                    }
                    break;
                }
            };
            _vpHome.Adapter = new FragmentAdapter(SupportFragmentManager, _fragmentList);
        }