//Change Tab font
        void ChangeFont()
        {
            var fontFace          = Typeface.CreateFromAsset(Context.Assets, "OpenSans-SemiBold.ttf");
            var bottomNavMenuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView;

            for (int i = 0; i < bottomNavMenuView.ChildCount; i++)
            {
                var item      = bottomNavMenuView.GetChildAt(i) as BottomNavigationItemView;
                var itemTitle = item.GetChildAt(1);

                var smallTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(0));
                var largeTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(1));

                lastItemId = bottomNavMenuView.SelectedItemId;

                smallTextView.SetTypeface(fontFace, TypefaceStyle.Bold);
                largeTextView.SetTypeface(fontFace, TypefaceStyle.Bold);
                smallTextView.SetTextSize(Android.Util.ComplexUnitType.Px, 24);
                largeTextView.SetTextSize(Android.Util.ComplexUnitType.Px, 24);

                //Set text color
                var textColor = (item.Id == bottomNavMenuView.SelectedItemId) ? Android.Graphics.Color.Black : Android.Graphics.Color.Gray;
                smallTextView.SetTextColor(textColor);
                largeTextView.SetTextColor(textColor);
            }
        }
Exemplo n.º 2
0
        private void UpdateTab(int tabIndex)
        {
            var page            = Element.GetChildPageWithTransform(tabIndex);
            var menu            = (BottomNavigationMenuView)_bottomNavigationView.GetChildAt(0);
            var isTitledisabled = TabbedPageTransforms.GetHideTitle(page);
            var view            = menu.GetChildAt(tabIndex);

            if (view == null)
            {
                return;
            }
            if (view is BottomNavigationItemView itemView)
            {
                itemView.SetShifting(false);
                itemView.SetBackground(null);
                itemView.SetBackgroundColor(Android.Graphics.Color.Transparent);
                for (int j = 0; j < itemView.ChildCount; j++)
                {
                    UIView childView = itemView.GetChildAt(j);
                    if (childView is BaselineLayout baselineLayout)
                    {
                        if (isTitledisabled)
                        {
                            childView.Visibility = ViewStates.Gone;
                            childView.SetPadding(0, 0, 0, 0);
                        }

                        for (int z = 0; z < baselineLayout.ChildCount; z++)
                        {
                            var textview = baselineLayout.GetChildAt(z);
                            textview.SetPadding(0, 0, 0, 0);
                            if (isTitledisabled)
                            {
                                textview.Visibility = ViewStates.Gone;
                            }
                        }
                    }
                    else if (isTitledisabled && childView is ImageView icon)
                    {
                        FrameLayout.LayoutParams parames = (FrameLayout.LayoutParams)icon.LayoutParameters;
                        parames.Height = LayoutParams.MatchParent;
                        parames.Width  = LayoutParams.MatchParent;
                        itemView.SetChecked(false);
                        parames.SetMargins(0, 8, 0, 8);
                    }
                }
            }
        }
        public static void RemoveShiftMode(BottomNavigationView bottomNavigationView)
        {
            try
            {
                if (bottomNavigationView == null)
                {
                    return;
                }
                var menuView     = (BottomNavigationMenuView)bottomNavigationView.GetChildAt(0);
                var shiftingMode = Java.Lang.Class.FromType(typeof(BottomNavigationMenuView)).GetDeclaredField("mShiftingMode");
                shiftingMode.Accessible = true;
                shiftingMode.SetBoolean(menuView, false);
                shiftingMode.Accessible = false;

                for (var i = 0; i < menuView.ChildCount; i++)
                {
                    var item = (BottomNavigationItemView)menuView.GetChildAt(i);
                    var icon = (AppCompatImageView)item.GetChildAt(0);

                    var layoutParameters = (AWidget.FrameLayout.LayoutParams)icon.LayoutParameters;
                    layoutParameters.Gravity = GravityFlags.Center;
                    item.SetShifting(false);
                    item.SetChecked(item.ItemData.IsChecked);
                }
            }
            catch (Exception e)
            {
            }
        }
Exemplo n.º 4
0
        public static void RemoveShiftMode(BottomNavigationView bottomNavigationView)
        {
            var bottomNavigationMenuView = (BottomNavigationMenuView)bottomNavigationView.GetChildAt(0);

            try
            {
                var shiftingMode = bottomNavigationMenuView.Class.GetDeclaredField("mShiftingMode");
                shiftingMode.Accessible = true;
                shiftingMode.SetBoolean(bottomNavigationMenuView, false);
                shiftingMode.Accessible = false;
                for (var i = 0; i < bottomNavigationMenuView.ChildCount; i++)
                {
                    var item = (BottomNavigationItemView)bottomNavigationMenuView.GetChildAt(i);
                    item.SetShiftingMode(false);
                    item.SetChecked(item.ItemData.IsChecked);
                }
            }
            catch (NoSuchFieldException)
            {
                Log.Error("ERROR NO SUCH FIELD", "Unable to get shift mode field");
            }
            catch (IllegalAccessException)
            {
                Log.Error("ERROR ILLEGAL ALG", "Unable to change value of shift mode");
            }
        }
Exemplo n.º 5
0
        void RemoveShiftMode(BottomNavigationView view)
        {
            var menuView = (BottomNavigationMenuView)view.GetChildAt(0);

            try
            {
                var shiftingMode = menuView.Class.GetDeclaredField("mShiftingMode");
                shiftingMode.Accessible = true;
                shiftingMode.SetBoolean(menuView, false);
                shiftingMode.Accessible = false;


                for (int i = 0; i < menuView.ChildCount; i++)
                {
                    var item = (BottomNavigationItemView)menuView.GetChildAt(i);
                    // item.SetShiftingMode(false);
                    // set once again checked value, so view will be updated
                    item.SetChecked(item.ItemData.IsChecked);
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine((ex.InnerException ?? ex).Message);
            }
        }
Exemplo n.º 6
0
        public static void disableShiftMode(BottomNavigationView view)
        {
            BottomNavigationMenuView menuView = (BottomNavigationMenuView)view.GetChildAt(0);

            try
            {
                for (int i = 0; i < menuView.ChildCount; i++)
                {
                    BottomNavigationItemView item = (BottomNavigationItemView)menuView.GetChildAt(i);
                    //noinspection RestrictedApi
                    item.SetShiftingMode(false);
                    // set once again checked value, so view will be updated
                    //noinspection RestrictedApi
                    item.SetChecked(item.ItemData.IsChecked);
                }
            }
            catch (NoSuchFieldException e)
            {
                //Log.("BNVHelper", "Unable to get shift mode field", e);
            }
            catch (IllegalAccessException e)
            {
                // Log.e("BNVHelper", "Unable to change value of shift mode", e);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// The ApplyBadge.
        /// </summary>
        /// <param name="badgeText">The badgeText<see cref="string"/>.</param>
        /// <param name="badgeBg">The badgeBg<see cref="Color"/>.</param>
        /// <param name="itemId">The itemId<see cref="int"/>.</param>
        /// <param name="textColor">The textColor<see cref="Color"/>.</param>
        private void ApplyBadge(string badgeText,
                                Color badgeBg, int itemId, Color textColor)
        {
            using BottomNavigationMenuView bottomNavigationMenuView =
                      (BottomNavigationMenuView)_bottomNavigationView.GetChildAt(0);
            var itemView = bottomNavigationMenuView
                           .FindViewById <BottomNavigationItemView>(itemId);

            if (string.IsNullOrEmpty(badgeText))
            {
                itemView.ApplyBadge(badgeBg, "", textColor);
            }
            else
            {
                int.TryParse(badgeText, out var badgeNumber);
                if (badgeNumber != 0)
                {
                    itemView.ApplyBadge(badgeBg, badgeText, textColor);
                }
                else
                {
                    itemView.ApplyTinyBadge(textColor);
                }
            }
        }
        private void UpdateAllTabs()
        {
            for (var index = 0; index < _formsTabs.Children.Count; index++)
            {
                var page = _formsTabs.Children[index].Navigation.NavigationStack.First();

                ((Android.Views.ViewGroup)((Android.Views.ViewGroup)_bottomNavigationView.GetChildAt(0)).GetChildAt(index)).GetChildAt(0).ContentDescription = page.Title ?? "Untitled";

                var androidTab = _bottomNavigationView.Menu.GetItem(index);
                int iconId;

                if (_formsTabs.Children[index]?.Navigation?.NavigationStack?.FirstOrDefault() is ITabPageIcons tabPage)
                {
                    if (_formsTabs.Children[index] == _formsTabs.CurrentPage)
                    {
                        iconId = ResourceUtil.GetDrawableIdByFileName(tabPage.GetSelectedIcon(), Context);
                        androidTab.SetIcon(iconId);
                        continue;
                    }

                    iconId = ResourceUtil.GetDrawableIdByFileName(tabPage.GetIcon(), Context);
                    androidTab.SetIcon(iconId);
                    continue;
                }
            }
        }
        protected virtual void SetBackgroundColor(BottomNavigationView bottomView, Color color)
        {
            if (_lastColor.IsDefault)
            {
                _lastColor = color;
            }

            using (var menuView = bottomView.GetChildAt(0) as BottomNavigationMenuView)
            {
                if (menuView == null)
                {
                    bottomView.SetBackground(new ColorDrawable(color.ToAndroid()));
                }
                else
                {
                    var index = _shellItem.Items.IndexOf(_shellItem.CurrentItem);
                    using (var menu = bottomView.Menu)
                        index = Math.Min(index, menu.Size() - 1);

                    using (var child = menuView.GetChildAt(index))
                    {
                        var touchPoint = new Point(child.Left + (child.Right - child.Left) / 2, child.Top + (child.Bottom - child.Top) / 2);

                        bottomView.Background?.Dispose();
                        bottomView.SetBackground(new ColorChangeRevealDrawable(_lastColor.ToAndroid(), color.ToAndroid(), touchPoint));
                        _lastColor = color;
                    }
                }
            }
        }
Exemplo n.º 10
0
        public static void disableShiftMode(BottomNavigationView navigationView)
        {
            BottomNavigationMenuView menuView = (BottomNavigationMenuView)navigationView.GetChildAt(0);


            try
            {
                var shiftingMode = typeof(BottomNavigationMenuView).GetField("mShiftingMode");

                //shiftingMode.setAccessible(true);
                //shiftingMode.setBoolean(menuView, false);
                //shiftingMode.SetValue(menuView, false);
                //shiftingMode.setAccessible(false);

                for (int i = 0; i < menuView.ChildCount; i++)
                {
                    BottomNavigationItemView itemView = (BottomNavigationItemView)menuView.GetChildAt(i);
                    itemView.SetShiftingMode(false);
                    itemView.SetChecked(itemView.ItemData.IsChecked);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 11
0
        private void UpdateTab(int tabIndex)
        {
            var page = Element.GetChildPageWithTransform(tabIndex);
            var menu = (BottomNavigationMenuView)_bottomNavigationView.GetChildAt(0);

            //Setting Title Property and Centering
            if (Transforms.GetHideTitle(page))
            {
                var view = menu.GetChildAt(tabIndex);
                if (view == null)
                {
                    return;
                }
                if (view is BottomNavigationItemView)
                {
                    var viewgroup = (ViewGroup)view;
                    for (int j = 0; j < viewgroup.ChildCount; j++)
                    {
                        View v = viewgroup.GetChildAt(j);
                        if (v is ViewGroup)
                        {
                            v.Visibility = ViewStates.Gone;
                        }
                        else
                        {
                            ImageView icon = (ImageView)v;
                            FrameLayout.LayoutParams parames = (FrameLayout.LayoutParams)icon.LayoutParameters;
                            parames.Gravity = GravityFlags.Center;
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        //Adding line view
        void SetupBottomNavigationView(BottomNavigationView bottomNavigationView, IMenuItem item)
        {
            //int lineBottomOffset = 8;
            //int lineWidth = 4;
            //int itemHeight = bottomNavigationView.Height - lineBottomOffset;
            //int itemWidth = (bottomNavigationView.Width / Element.Children.Count);
            //int leftOffset = item.ItemId * itemWidth;
            //int rightOffset = itemWidth * (Element.Children.Count - (item.ItemId + 1));
            //GradientDrawable bottomLine = new GradientDrawable();
            //bottomLine.SetShape(ShapeType.Line);
            //bottomLine.SetStroke(lineWidth, Xamarin.Forms.Color.DarkGray.ToAndroid());

            //var layerDrawable = new LayerDrawable(new Drawable[] { bottomLine });
            //layerDrawable.SetLayerInset(0, leftOffset, itemHeight, rightOffset, 0);

            //bottomNavigationView.SetBackground(layerDrawable);
            var bottomNavMenuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView;

            bottomNavMenuView.GetChildAt(0).SetBackgroundResource(Resource.Drawable.rect);
            bottomNavMenuView.GetChildAt(1).SetBackgroundResource(Resource.Drawable.rect);
            bottomNavMenuView.GetChildAt(2).SetBackgroundResource(Resource.Drawable.rect);
            bottomNavMenuView.GetChildAt(3).SetBackgroundResource(Resource.Drawable.rect);
            bottomNavMenuView.GetChildAt(4).SetBackgroundResource(Resource.Drawable.rect);
            bottomNavMenuView.GetChildAt(item.ItemId).SetBackgroundResource(Resource.Drawable.rectangle);
        }
Exemplo n.º 13
0
 //Remove animation
 public void SetShiftMode(BottomNavigationView bottomNavigationView, bool enableShiftMode, bool enableItemShiftMode)
 {
     try
     {
         var menuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView;
         if (menuView == null)
         {
             System.Diagnostics.Debug.WriteLine("Unable to find BottomNavigationMenuView");
             return;
         }
         var shiftMode = menuView.Class.GetDeclaredField("mShiftingMode");
         shiftMode.Accessible = true;
         shiftMode.SetBoolean(menuView, enableShiftMode);
         shiftMode.Accessible = false;
         shiftMode.Dispose();
         for (int i = 0; i < menuView.ChildCount; i++)
         {
             var item = menuView.GetChildAt(i) as BottomNavigationItemView;
             if (item == null)
             {
                 continue;
             }
             item.SetShifting(enableItemShiftMode);
             item.SetChecked(item.ItemData.IsChecked);
         }
         menuView.UpdateMenuView();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine($"Unable to set shift mode: {ex}");
     }
 }
Exemplo n.º 14
0
        protected virtual void SetBackgroundColor(BottomNavigationView bottomView, Color color)
        {
            var    menuView                  = bottomView.GetChildAt(0) as BottomNavigationMenuView;
            var    oldBackground             = bottomView.Background;
            var    colorDrawable             = oldBackground as ColorDrawable;
            var    colorChangeRevealDrawable = oldBackground as ColorChangeRevealDrawable;
            AColor lastColor                 = colorChangeRevealDrawable?.EndColor ?? colorDrawable?.Color ?? Colors.Transparent.ToPlatform();
            AColor newColor;

            if (color == null)
            {
                newColor = ShellView.DefaultBottomNavigationViewBackgroundColor.ToPlatform();
            }
            else
            {
                newColor = color.ToPlatform();
            }

            if (menuView == null)
            {
                if (colorDrawable != null && lastColor == newColor)
                {
                    return;
                }

                if (lastColor != newColor || colorDrawable == null)
                {
                    // taken from android source code
                    var backgroundColor = new MaterialShapeDrawable();
                    backgroundColor.FillColor = ColorStateList.ValueOf(newColor);
                    backgroundColor.InitializeElevationOverlay(bottomView.Context);

                    ViewCompat.SetBackground(bottomView, backgroundColor);
                }
            }
            else
            {
                if (colorChangeRevealDrawable != null && lastColor == newColor)
                {
                    return;
                }

                var index = ((IShellItemController)_shellItem).GetItems().IndexOf(_shellItem.CurrentItem);
                var menu  = bottomView.Menu;
                index = Math.Min(index, menu.Size() - 1);

                var child = menuView.GetChildAt(index);
                if (child == null)
                {
                    return;
                }

                var touchPoint = new Point(child.Left + (child.Right - child.Left) / 2, child.Top + (child.Bottom - child.Top) / 2);

                ViewCompat.SetBackground(bottomView, new ColorChangeRevealDrawable(lastColor, newColor, touchPoint));
            }
        }
Exemplo n.º 15
0
        void SetSelectedTtitle()
        {
            var bottomNavMenuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView;

            for (int i = 0; i < bottomNavMenuView.ChildCount; i++)
            {
                var item = bottomNavMenuView.GetChildAt(i) as BottomNavigationItemView;

                var itemTitle = item.GetChildAt(1);

                var largeTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(1));

                lastItemId = bottomNavMenuView.SelectedItemId;
                largeTextView.SetTypeface(Typeface.Default, TypefaceStyle.Bold);

                //Set text color
                var textColor = (item.Id == bottomNavMenuView.SelectedItemId) ? tabbedPage.On <Xamarin.Forms.PlatformConfiguration.Android>().GetBarSelectedItemColor().ToAndroid() : tabbedPage.On <Xamarin.Forms.PlatformConfiguration.Android>().GetBarItemColor().ToAndroid();
                largeTextView.SetTextColor(textColor);
            }
        }
Exemplo n.º 16
0
        public static void SetShifting(this BottomNavigationView bnv, bool shifting)
        {
            var bnmv = (BottomNavigationMenuView)bnv.GetChildAt(0);

            for (int i = 0; i < bnmv.ChildCount; i++)
            {
                var bniv = (BottomNavigationItemView)bnmv.GetChildAt(i);
                bniv.SetShifting(shifting);
                bniv.SetChecked(bniv.ItemData.IsChecked);
            }
        }
        public static void SetShiftMode(this BottomNavigationView bottomNavigationView, bool enableShiftMode, bool enableItemShiftMode)
        {
            try
            {
                using (var menuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView)
                {
                    if (menuView == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Unable to find BottomNavigationMenuView");
                        return;
                    }

#if __ANDROID81__
                    var shiftMode = menuView.Class.GetDeclaredField("mShiftingMode");
                    shiftMode.Accessible = true;
                    shiftMode.SetBoolean(menuView, enableShiftMode);
                    shiftMode.Accessible = false;
                    shiftMode.Dispose();
#else
                    if (enableShiftMode)
                    {
                        bottomNavigationView.LabelVisibilityMode = ALabelVisibilityMode.LabelVisibilityAuto;
                    }
                    else
                    {
                        bottomNavigationView.LabelVisibilityMode = ALabelVisibilityMode.LabelVisibilityLabeled;
                    }
#endif

                    for (int i = 0; i < menuView.ChildCount; i++)
                    {
                        var child = menuView.GetChildAt(i);
                        var item  = child as BottomNavigationItemView;
                        if (item != null)
                        {
#if __ANDROID81__
                            item.SetShiftingMode(enableItemShiftMode);
#else
                            item.SetShifting(enableItemShiftMode);
#endif
                            item.SetChecked(item.ItemData.IsChecked);
                        }

                        child.Dispose();
                    }

                    menuView.UpdateMenuView();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Unable to set shift mode: {ex}");
            }
        }
Exemplo n.º 18
0
        public static void SetLabelVisibilityMode(this BottomNavigationView bnv, int mode)
        {
            var bnmv = (BottomNavigationMenuView)bnv.GetChildAt(0);

            using (var field = bnmv.Class.GetDeclaredField("labelVisibilityMode"))
            {
                field.Accessible = true;
                field.SetInt(bnmv, mode);
                field.Accessible = false;
            }
        }
        protected virtual void SetBackgroundColor(BottomNavigationView bottomView, Color color)
        {
            var    menuView                  = bottomView.GetChildAt(0) as BottomNavigationMenuView;
            var    oldBackground             = bottomView.Background;
            var    colorDrawable             = oldBackground as ColorDrawable;
            var    colorChangeRevealDrawable = oldBackground as ColorChangeRevealDrawable;
            AColor lastColor                 = colorChangeRevealDrawable?.EndColor ?? colorDrawable?.Color ?? Color.Default.ToAndroid();
            AColor newColor;

            if (color == Color.Default)
            {
                newColor = Color.White.ToAndroid();
            }
            else
            {
                newColor = color.ToAndroid();
            }

            if (menuView == null)
            {
                if (colorDrawable != null && lastColor == newColor)
                {
                    return;
                }

                if (lastColor != newColor || colorDrawable == null)
                {
                    bottomView.SetBackground(new ColorDrawable(newColor));
                }
            }
            else
            {
                if (colorChangeRevealDrawable != null && lastColor == newColor)
                {
                    return;
                }

                var index = ((IShellItemController)_shellItem).GetItems().IndexOf(_shellItem.CurrentItem);
                var menu  = bottomView.Menu;
                index = Math.Min(index, menu.Size() - 1);

                var child = menuView.GetChildAt(index);
                if (child == null)
                {
                    return;
                }

                var touchPoint = new Point(child.Left + (child.Right - child.Left) / 2, child.Top + (child.Bottom - child.Top) / 2);

                bottomView.SetBackground(new ColorChangeRevealDrawable(lastColor, newColor, touchPoint));
            }
        }
        //Change Tab font
        void ChangeFont()
        {
            var fontFace          = Typeface.CreateFromAsset(Context.Assets, "Celias-Medium.ttf");
            var bottomNavMenuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView;

            for (int i = 0; i < bottomNavMenuView.ChildCount; i++)
            {
                var item      = bottomNavMenuView.GetChildAt(i) as BottomNavigationItemView;
                var itemTitle = item.GetChildAt(1);

                var smallTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(0));
                var largeTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(1));

                lastItemId = bottomNavMenuView.SelectedItemId;

                smallTextView.SetTypeface(fontFace, TypefaceStyle.Normal);
                largeTextView.SetTypeface(fontFace, TypefaceStyle.Normal);

                smallTextView.SetTextSize(Android.Util.ComplexUnitType.Sp, 10);
                largeTextView.SetTextSize(Android.Util.ComplexUnitType.Sp, 12);
            }
        }
Exemplo n.º 21
0
        //Change Tab font
        void ChangeFont()
        {
            var fontFace          = Typeface.CreateFromAsset(Context.Assets, "gilsansultrabold.ttf");
            var bottomNavMenuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView;

            for (int i = 0; i < bottomNavMenuView.ChildCount; i++)
            {
                var item      = bottomNavMenuView.GetChildAt(i) as BottomNavigationItemView;
                var itemTitle = item.GetChildAt(1);

                var smallTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(0));
                var largeTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(1));

                lastItemId = bottomNavMenuView.SelectedItemId;

                smallTextView.SetTypeface(fontFace, TypefaceStyle.Bold);
                largeTextView.SetTypeface(fontFace, TypefaceStyle.Bold);

                //Set text color
                var textColor = (item.Id == bottomNavMenuView.SelectedItemId) ? tabbedPage.On <Xamarin.Forms.PlatformConfiguration.Android>().GetBarSelectedItemColor().ToAndroid() : tabbedPage.On <Xamarin.Forms.PlatformConfiguration.Android>().GetBarItemColor().ToAndroid();
                smallTextView.SetTextColor(textColor);
                largeTextView.SetTextColor(textColor);
            }
        }
Exemplo n.º 22
0
        //Change Tab font
        void ChangeFont()
        {
            var fontFace          = Typeface.CreateFromAsset(Context.Assets, fontFamily);
            var bottomNavMenuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView;

            for (int i = 0; i < bottomNavMenuView.ChildCount; i++)
            {
                var item      = bottomNavMenuView.GetChildAt(i) as BottomNavigationItemView;
                var itemTitle = item.GetChildAt(1);

                var smallTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(0));
                var largeTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(1));

                lastItemId = bottomNavMenuView.SelectedItemId;

                smallTextView.SetTypeface(fontFace, TypefaceStyle.Bold);
                largeTextView.SetTypeface(fontFace, TypefaceStyle.Bold);

                //Set text color
                var textColor = (item.Id == bottomNavMenuView.SelectedItemId) ? tabbedPage.SelectedTabColor.ToAndroid() : tabbedPage.UnselectedTabColor.ToAndroid();
                smallTextView.SetTextColor(textColor);
                largeTextView.SetTextColor(textColor);
            }
        }
        void RemoveShiftMode(BottomNavigationView view)
        {
            var menuView = (BottomNavigationMenuView)view.GetChildAt(0);

            try
            {
                //view.ScaleY = (float)1.1;
                var shiftingMode = menuView.Class.GetDeclaredField("mShiftingMode");
                shiftingMode.Accessible = true;
                shiftingMode.SetBoolean(menuView, false);
                shiftingMode.Accessible = false;

                for (int i = 0; i < menuView.ChildCount; i++)
                {
                    var item = (BottomNavigationItemView)menuView.GetChildAt(i);
                    item.SetShiftingMode(false);
                    // set once again checked value, so view will be updated
                    item.SetChecked(true);
                    item.SetShiftingMode(false);
                    if (i == 0)
                    {
                        item.LongClick += HomeLongClickListener;
                    }
                    if (i == 2)
                    {
                        item.LongClick += FeedTabLongClickListener;
                    }
                    if (i == 3)
                    {
                        item.LongClick += MyChannelLongClickListener;
                    }
                    if (i == 4)
                    {
                        item.LongClick += SettingsTabLongClickListener;
                    }
                    if (NavViewItemList != null)
                    {
                        NavViewItemList.Add(item);
                    }
                }
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine((ex.InnerException ?? ex).Message);
            }
        }
Exemplo n.º 24
0
        public static void UpdateBottomNavTitleFont(this BottomNavigationView view)
        {
            var menuView = (BottomNavigationMenuView)view.GetChildAt(0);

            try
            {
                for (int i = 0; i < menuView.ChildCount; i++)
                {
                    var item = (BottomNavigationItemView)menuView.GetChildAt(i);
                    // set once again checked value, so view will be updated
                    //noinspection RestrictedApi
                    item.SetChecked(item.ItemData.IsChecked);
                    //Custom Style Title
                }
                menuView.UpdateMenuView();
            }
            catch (Exception ex)
            {
            }
        }
        void ChangeFont()
        {
            var fontFace = Typeface.CreateFromAsset(Context?.Assets, "nexabold.otf");

            if (!(_bottomNavigationView.GetChildAt(0) is BottomNavigationMenuView bottomNavMenuView))
            {
                return;
            }

            for (var i = 0; i < bottomNavMenuView.ChildCount; i++)
            {
                var item      = bottomNavMenuView.GetChildAt(i) as BottomNavigationItemView;
                var itemTitle = item?.GetChildAt(1);

                var smallTextView = (TextView)((BaselineLayout)itemTitle)?.GetChildAt(0);
                var largeTextView = (TextView)((BaselineLayout)itemTitle)?.GetChildAt(1);

                smallTextView?.SetTypeface(fontFace, TypefaceStyle.Normal);
                largeTextView?.SetTypeface(fontFace, TypefaceStyle.Normal);
            }
        }
Exemplo n.º 26
0
        void ChangeFont()
        {
            var fontFace = Typeface.CreateFromAsset(Context.Assets, "SourceSansPro-Regular.ttf");

            if (bottomNavigationView.GetChildAt(0) is not BottomNavigationMenuView bottomNavMenuView)
            {
                return;
            }

            for (var i = 0; i < bottomNavMenuView.ChildCount; i++)
            {
                var item      = bottomNavMenuView.GetChildAt(i) as BottomNavigationItemView;
                var itemTitle = item.GetChildAt(1);

                var smallTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(0));
                var largeTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(1));

                smallTextView.SetTypeface(fontFace, TypefaceStyle.Normal);
                largeTextView.SetTypeface(fontFace, TypefaceStyle.Normal);
            }
        }
Exemplo n.º 27
0
        public static void DisableShiftMode(BottomNavigationView view)
        {
            BottomNavigationMenuView menuView = (BottomNavigationMenuView)view.GetChildAt(0);

            try
            {
                var sm = menuView.Class.GetDeclaredField("mShiftingMode");
                sm.Accessible = true;
                sm.SetBoolean(menuView, false);
                sm.Accessible = false;
                for (int i = 0; i < menuView.ChildCount; i++)
                {
                    BottomNavigationItemView item = (BottomNavigationItemView)menuView.GetChildAt(i);
                    item.SetShiftingMode(false);
                    item.SetChecked(item.ItemData.IsChecked);
                }
            }
            catch (System.Exception)
            {
            }
        }
        public static void DisableShiftMode(BottomNavigationView view)
        {
            BottomNavigationMenuView menuView = (BottomNavigationMenuView)view.GetChildAt(0);

            try
            {
                Java.Lang.Reflect.Field shiftingMode = menuView.Class.GetDeclaredField("mShiftingMode");
                shiftingMode.Accessible = true;
                shiftingMode.SetBoolean(menuView, false);
                shiftingMode.Accessible = false;
                for (int i = 0; i < menuView.ChildCount; i++)
                {
                    BottomNavigationItemView itemView = (BottomNavigationItemView)menuView.GetChildAt(i);
                    itemView.SetShiftingMode(false);
                    itemView.SetChecked(itemView.ItemData.IsChecked);
                }
            }
            catch (Exception ex)
            {
                BuglyUtil.PostException("unable to get shift mode field" + ex);
            }
        }
Exemplo n.º 29
0
        public static void DisableScale(this BottomNavigationView bnv)
        {
            var bnmv      = (BottomNavigationMenuView)bnv.GetChildAt(0);
            var fontScale = bnv.Resources.DisplayMetrics.ScaledDensity;

            for (int i = 0; i < bnmv.ChildCount; i++)
            {
                var bniv = (BottomNavigationItemView)bnmv.GetChildAt(i);
                using (var field0 = bniv.Class.GetDeclaredField("largeLabel"))
                    using (var field1 = bniv.Class.GetDeclaredField("smallLabel"))
                        using (var field2 = bniv.Class.GetDeclaredField("shiftAmount"))
                            using (var field3 = bniv.Class.GetDeclaredField("scaleUpFactor"))
                                using (var field4 = bniv.Class.GetDeclaredField("scaleDownFactor"))
                                {
                                    field0.Accessible = true;
                                    field1.Accessible = true;
                                    field2.Accessible = true;
                                    field3.Accessible = true;
                                    field4.Accessible = true;

                                    var tvLarge = field0.Get(bniv).JavaCast <TextView>();
                                    var tvSmall = field1.Get(bniv).JavaCast <TextView>();
                                    tvLarge.TextSize = tvSmall.TextSize / fontScale;
                                    field2.Set(bniv, 0);
                                    field3.Set(bniv, 1F);
                                    field4.Set(bniv, 1F);

                                    field0.Accessible = false;
                                    field1.Accessible = false;
                                    field2.Accessible = false;
                                    field3.Accessible = false;
                                    field4.Accessible = false;
                                }
                bniv.SetChecked(bniv.ItemData.IsChecked);
            }
        }
        BottomNavigationView CustomizeBottomNavigationViewMenuItems(BottomNavigationView bottomNavigationView, List <TabStates.TabFragPackage> tabs = null, bool setExisting = false, bool removeShiftMode = true)
        {
            BottomNavigationMenuView menuView = (BottomNavigationMenuView)bottomNavigationView.GetChildAt(0);

            try {
                //view.ScaleY = (float)1.1;
                var shiftingMode = menuView.Class.GetDeclaredField("mShiftingMode");
                shiftingMode.Accessible = true;
                shiftingMode.SetBoolean(menuView, false);
                shiftingMode.Accessible = false;
            }
            catch {  }
            var positionKey = -1;

            if (!setExisting && tabs != null)
            {
                foreach (var tab in tabs)
                {
                    positionKey++;
                    var item = (BottomNavigationItemView)menuView.GetChildAt(positionKey);
                    item.SetShiftingMode(false);
                    // set once again checked value, so view will be updated
                    item.SetChecked(true);
                    //BottomNavigationItemView tab = new BottomNavigationItemView(GetMainContext());
                    item.SetIcon(tab.Icon);
                    item.SetEnabled(true);
                    item.SetTitle(tab.Title);
                    item.ItemPosition = positionKey;
                    //menuView.AddView(tab, positionKey);
                }
            }
            else if (setExisting && tabs != null)
            {
                for (int i = 0; i < menuView.ChildCount; i++)
                {
                    try {
                        GetBottomNavItemFromView(menuView.GetChildAt(i)).SetShiftingMode(false);
                        GetBottomNavItemFromView(menuView.GetChildAt(i)).ItemData.SetIcon(tabs[i].Icon);
                        GetBottomNavItemFromView(menuView.GetChildAt(i)).ItemData.SetTitle(tabs[i].Title);
                        GetBottomNavItemFromView(menuView.GetChildAt(i)).SetChecked(true);
                        if (i == 0)
                        {
                            GetBottomNavItemFromView(menuView.GetChildAt(i)).LongClick += HomeLongClickListener;
                        }
                        if (i == 2)
                        {
                            GetBottomNavItemFromView(menuView.GetChildAt(i)).LongClick += FeedTabLongClickListener;
                        }
                        if (i == 3)
                        {
                            GetBottomNavItemFromView(menuView.GetChildAt(i)).LongClick += MyChannelLongClickListener;
                        }
                        if (i == 4)
                        {
                            GetBottomNavItemFromView(menuView.GetChildAt(i)).LongClick += SettingsTabLongClickListener;
                        }
                    }
                    catch { }
                    try
                    {
                        NavViewItemList.Add(GetBottomNavItemFromView(menuView.GetChildAt(i)));
                    }
                    catch { }
                }
            }

            return(bottomNavigationView);
        }