Modify the animation effect when BottomNavigationView has more than 3 Items

I was working on a project today and used BottomNavigationView to add multiple items. When there were more than three items, the title text was hidden and would only be displayed when selected. This did not meet the design requirements of the project, so I looked for ways to modify it.

After some searching on Baidu and Google, I found that the following reflection method is basically used to remove animation effects:

Then I followed this method and found that item.setShiftingMode(false); reported an error. Then I searched for shift and found that this method item.setShifting(false); was running, but it had no effect.

Then I found that my design and v7 packages had higher versions:

Okay, let’s keep looking, and finally found the answer on a foreign website:

As Jolanda Verhoef pointed out the new Support library (28.0.1-alpha1) and also the new Material Components library (1.0.0-beta01) offers a public property which can be used to manipulate the shifting mode over 3 menu items.

Under your BottomNavigationView layout, labelVisibilityMode has multiple animation options, which can be modified according to your needs:

It is estimated that the higher version provides multiple animation options, making modifications more convenient. For lower versions, you can continue to use the previous reflection method to modify!

Reference question link:https://stackoverflow.com/questions/40176244/how-to-disable-bottomnavigationview-shift-mode

 

I hope it can be helpful to everyone. If you like it, please give it a follow!

Guess you like

Origin blog.csdn.net/Cy_Shay/article/details/82630358