10

enter image description here

BottomNavigationView doesn't allow disabling shift mode has this issue fixed in new version of support library?

Also there are some solutions which use reflection mechanism I don't think its right way is there any solution to this major problem.

All ready seen this solution don't want to use this

Community
  • 1
  • 1
amodkanthe
  • 4,345
  • 6
  • 36
  • 77
  • Looking for a solution to the same problem. – Umang Mathur Jan 13 '17 at 08:53
  • An alternative is to just ditch the BottomNavigationView from the support lib and write your own layout with a horizontal LinearLayout that contains vertical LinearLayouts with an ImageView and a TextView, and you manage the item selection state. – EpicPandaForce Apr 17 '19 at 09:28

4 Answers4

4

If possible then update to android sdk-28 then add app:labelVisibilityMode="labeled" in your xml.

Bali
  • 749
  • 6
  • 19
1

You just need to update to 28.0.0 support library! They already provided setLabelVisibilityMode() method to disable the shifting

navButton.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);

for more info, check this out https://developer.android.com/reference/com/google/android/material/bottomnavigation/LabelVisibilityMode.html#LABEL_VISIBILITY_SELECTED

Fadzli Razali
  • 145
  • 1
  • 6
0

Hello I have face the same problem and I know that its tedious task to load reflect java library in xamarin android.

But thanks to "James Montemagno" to come with its solution. Here is the link you can follow and got the result you want!

It worked for me hope it will for you too. Happy coding! :)

Link: https://montemagno.com/remove-shifting-bottomnavigationview-android/

Git Post: https://github.com/jamesmontemagno/Xamarin-Templates/blob/master/Xamarin.Android-Templates/Projects/BottomTabsApp/BlankAppCompat/BottomNavigationViewUtils.cs

public static class BottomNavigationViewUtils {

    /// <summary>
    /// Enable or disable shift mode on bottom navigation view
    /// </summary>

    public static void SetShiftMode(this 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.SetShiftingMode(enableItemShiftMode);
                item.SetChecked(item.ItemData.IsChecked);

            }

            menuView.UpdateMenuView();
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine($"Unable to set shift mode: {ex}");
        }
    }
}

Than Use it:

var bottomNavigationView = FindViewById(Resource.Id.bottomNavigationBar); bottomNavigationView.SetShiftMode(false,false);

Divyesh
  • 2,085
  • 20
  • 35
  • Welcome to StackOverflow! Here, posting a link is not enough, please ensure that your answer will be useful in the future if those links are not working anymore: quote the relevant parts of the pages **inside your post**. – juzraai Sep 23 '17 at 11:06
  • 4
    This uses reflection. – Rob Pridham Jan 04 '18 at 11:37
0

Just add this in your dimens.. worked for me!

<dimen name="design_bottom_navigation_active_text_size">12sp</dimen>
M_droid
  • 2,447
  • 2
  • 25
  • 35