public static BottomNavigationViewEx SetupBottomBar(this ExtendedTabbedPageRenderer renderer,
                                                            global::Android.Widget.RelativeLayout rootLayout, BottomNavigationViewEx bottomNav, int barId)
        {
            if (bottomNav != null)
            {
                rootLayout.RemoveView(bottomNav);
                bottomNav.SetOnNavigationItemSelectedListener(null);
            }

            var barParams = new global::Android.Widget.RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                ExtendedTabbedPageRenderer.BottomBarHeight.HasValue ?
                (int)rootLayout.Context.ToPixels(ExtendedTabbedPageRenderer.BottomBarHeight.Value) :
                ViewGroup.LayoutParams.WrapContent);

            barParams.AddRule(LayoutRules.AlignParentBottom);
            bottomNav = new BottomNavigationViewEx(rootLayout.Context)
            {
                LayoutParameters = barParams,
                Id = barId
            };
            if (ExtendedTabbedPageRenderer.BackgroundColor.HasValue)
            {
                bottomNav.SetBackgroundColor(ExtendedTabbedPageRenderer.BackgroundColor.Value);
            }

            bottomNav.SetOnNavigationItemSelectedListener(renderer);
            rootLayout.AddView(bottomNav, 1, barParams);

            return(bottomNav);
        }
示例#2
0
        protected override async void OnElementChanged(ElementChangedEventArgs <BottomBarPage> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                _element = e.NewElement;
                if (_bottomNavigationView == null)
                {
                    _rootLayout = new Android.Widget.RelativeLayout(Context)
                    {
                        LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                    };
                    AddView(_rootLayout);

                    _frameLayout = new FrameLayout(Context)
                    {
                        LayoutParameters = new ActionBar.LayoutParams(LayoutParams.MatchParent,
                                                                      LayoutParams.MatchParent, GravityFlags.Fill)
                    };
                    _rootLayout.AddView(_frameLayout);

                    _bottomNavigationView = new BottomNavigationViewEx(Context)
                    {
                        LayoutParameters =
                            new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent,
                                                                           LayoutParams.WrapContent)
                    };
                    (_bottomNavigationView.LayoutParameters as Android.Widget.RelativeLayout.LayoutParams)?.AddRule(LayoutRules.AlignParentBottom);
                    _bottomNavigationView.SetOnNavigationItemSelectedListener(this);

                    if (_element.BarTextColor != default(Color))
                    {
                        _bottomNavigationView.ItemTextColor    = ColorStateList.ValueOf(_element.BarTextColor.ToAndroid());
                        _bottomNavigationView.ItemIconTintList = ColorStateList.ValueOf(_element.BarTextColor.ToAndroid());
                    }

                    if (_element.BarBackgroundColor != default(Color))
                    {
                        _bottomNavigationView.SetBackgroundColor(_element.BarBackgroundColor.ToAndroid());
                    }

                    foreach (var page in Element.Children)
                    {
                        await AddPage(page);
                    }

                    _rootLayout.AddView(_bottomNavigationView, 1);
                    _bottomNavigationView.EnableShiftingMode(false);
                    _bottomNavigationView.EnableItemShiftingMode(false);
                    ChangeCurrentPage(Element.Children[0]);
                    _element.ChildAdded   += Element_ChildAdded;
                    _element.ChildRemoved += Element_ChildRemoved;
                }
            }
        }
示例#3
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName == TabbedPage.BarBackgroundColorProperty.PropertyName)
            {
                _bottomNavigationView.SetBackgroundColor(Element.BarBackgroundColor.ToAndroid());
            }
            else if (e.PropertyName == TabbedPage.BarTextColorProperty.PropertyName)
            {
                _bottomNavigationView.ItemTextColor = ColorStateList.ValueOf(Element.BarTextColor.ToAndroid());
            }
        }
示例#4
0
        public static BottomNavigationViewEx SetupBottomBar(this BottomTabbedRenderer renderer, Android.Widget.RelativeLayout rootLayout, BottomNavigationViewEx bottomNav, int barId)
        {
            if (bottomNav != null)
            {
                rootLayout.RemoveView(bottomNav);
                bottomNav.SetOnNavigationItemSelectedListener(null);
            }

            var barParams = new Android.Widget.RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                BottomTabbedRenderer.BottomBarHeight.HasValue ? (int)rootLayout.Context.ToPixels(BottomTabbedRenderer.BottomBarHeight.Value) : ViewGroup.LayoutParams.WrapContent);

            //Add alignment rules to close to the lower edge of the parent contro
            barParams.AddRule(LayoutRules.AlignParentBottom);
            bottomNav = new BottomNavigationViewEx(rootLayout.Context)
            {
                LayoutParameters = barParams,
                Id = barId
            };
            if (BottomTabbedRenderer.BackgroundColor.HasValue)
            {
                bottomNav.SetBackgroundColor(BottomTabbedRenderer.BackgroundColor.Value);
            }
            if (BottomTabbedRenderer.ItemIconTintList != null)
            {
                bottomNav.ItemIconTintList = BottomTabbedRenderer.ItemIconTintList;
            }
            if (BottomTabbedRenderer.ItemTextColor != null)
            {
                bottomNav.ItemTextColor = BottomTabbedRenderer.ItemTextColor;
            }
            if (BottomTabbedRenderer.ItemBackgroundResource.HasValue)
            {
                bottomNav.ItemBackgroundResource = BottomTabbedRenderer.ItemBackgroundResource.Value;
            }
            //The listening callback method "setOnNavigationItemSelectedListener()", which defaults to the first entry being the first item selected, can be set by
            //"navigation.getMenu().getItem(index).setChecked(true);"
            bottomNav.SetOnNavigationItemSelectedListener(renderer);
            rootLayout.AddView(bottomNav, 1, barParams);

            return(bottomNav);
        }
        public static BottomNavigationViewEx SetupBottomBar(this BottomTabbedRenderer renderer, Android.Widget.RelativeLayout rootLayout, BottomNavigationViewEx bottomNav, int barId)
        {
            if (bottomNav != null)
            {
                rootLayout.RemoveView(bottomNav);
                bottomNav.SetOnNavigationItemSelectedListener(null);
            }

            var barParams = new Android.Widget.RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                BottomTabbedRenderer.BottomBarHeight.HasValue ? (int)rootLayout.Context.ToPixels(BottomTabbedRenderer.BottomBarHeight.Value) : ViewGroup.LayoutParams.WrapContent);

            barParams.AddRule(LayoutRules.AlignParentBottom);
            bottomNav = new BottomNavigationViewEx(rootLayout.Context)
            {
                LayoutParameters = barParams,
                Id = barId
            };
            if (BottomTabbedRenderer.BackgroundColor.HasValue)
            {
                bottomNav.SetBackgroundColor(BottomTabbedRenderer.BackgroundColor.Value);
            }
            if (BottomTabbedRenderer.ItemIconTintList != null)
            {
                bottomNav.ItemIconTintList = BottomTabbedRenderer.ItemIconTintList;
            }
            if (BottomTabbedRenderer.ItemTextColor != null)
            {
                bottomNav.ItemTextColor = BottomTabbedRenderer.ItemTextColor;
            }
            if (BottomTabbedRenderer.ItemBackgroundResource.HasValue)
            {
                bottomNav.ItemBackgroundResource = BottomTabbedRenderer.ItemBackgroundResource.Value;
            }

            bottomNav.SetOnNavigationItemSelectedListener(renderer);
            rootLayout.AddView(bottomNav, 1, barParams);

            return(bottomNav);
        }
示例#6
0
        protected override void OnElementChanged(ElementChangedEventArgs <BottomTabbedPage> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                BottomTabbedPage bottomBarPage = e.NewElement;

                if (_bottomBar == null)
                {
                    _pageController = PageController.Create(bottomBarPage);

                    _rootLayout = new LinearLayout(Context)
                    {
                        LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                    };
                    AddView(_rootLayout);

                    // create a view which will act as container for Page's
                    _frameLayout = new FrameLayout(Context)
                    {
                        LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                    };
                    _rootLayout.AddView(_frameLayout);

                    _bottomBar = new BottomNavigationViewEx(Context)
                    {
                        LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                    };

                    _rootLayout.AddView(_bottomBar);
                    _bottomBar.SetOnNavigationItemSelectedListener(this);

                    if (BackgroundColor.HasValue)
                    {
                        _bottomBar.SetBackgroundColor(BackgroundColor.Value);
                    }

                    if (ItemIconTintList != null)
                    {
                        _bottomBar.ItemIconTintList = ItemIconTintList;
                    }
                    if (ItemTextColor != null)
                    {
                        _bottomBar.ItemTextColor = ItemTextColor;
                    }
                    if (ItemBackgroundResource.HasValue)
                    {
                        _bottomBar.ItemBackgroundResource = ItemBackgroundResource.Value;
                    }
                    // Resource.Drawable.bnv_selector

                    _menu = (BottomNavigationMenu)_bottomBar.Menu;

                    UpdateTabs();
                }

                if (bottomBarPage.CurrentPage != null)
                {
                    SwitchContent(bottomBarPage.CurrentPage);
                }
            }
        }