Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove icon animation for bottom navigation view in android

I have implemented Bottom Navigation View from Design Support Library 25 in my project. I have 5 icons in the view. whenever an icon is selected it's having some animation. But when 3 or fewer icons is not showing any animations. I want to remove that animation and need only some color change for the icon. How can I achieve this? Done enough googling, but couldn't find the solution. Please help. Thanks.

like image 712
Nabeel K Avatar asked Jan 14 '17 11:01

Nabeel K


People also ask

How do I turn off the bottom navigation on my Android?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How do I change the order of the bottom navigation bar in Android?

You can also adjust the order of the buttons on the Navigation bar. From Settings, tap Display, and then tap Navigation bar. Make sure Buttons is selected, and then you can choose your desired button setup at the bottom of the screen.

What is bottom navigation view in Android?

Bottom navigation bars make it easy for users to explore and switch between top-level views in a single tap. They should be used when an application has three to five top-level destinations.


3 Answers

got answer from this thread.

To remove animation or shift mode.

Implementation of BottomNavigationView has condition: when there is more than 3 items then use shift mode.

Create helper class

import android.support.design.internal.BottomNavigationItemView;  import android.support.design.internal.BottomNavigationMenuView;  import android.support.design.widget.BottomNavigationView;  import android.util.Log; import java.lang.reflect.Field;  public class BottomNavigationViewHelper {      public static void disableShiftMode(BottomNavigationView view) {         BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);         try {              Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");             shiftingMode.setAccessible(true);             shiftingMode.setBoolean(menuView, false);             shiftingMode.setAccessible(false);             for (int i = 0; i < menuView.getChildCount(); 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.getItemData().isChecked());             }          } catch (NoSuchFieldException e) {             Log.e("BNVHelper", "Unable to get shift mode field", e);         } catch (IllegalAccessException e) {             Log.e("BNVHelper", "Unable to change value of shift mode", e);         }      }  }  

Usage

BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_bar); BottomNavigationViewHelper.disableShiftMode(bottomNavigationView); 
like image 200
Nabeel K Avatar answered Sep 28 '22 07:09

Nabeel K


I tryed this and it worked well

BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);

Or this code mainactivity.xml

app:labelVisibilityMode="unlabeled"
like image 26
Azad Qaderzadeh Avatar answered Sep 28 '22 05:09

Azad Qaderzadeh


I just add this code on dimens.xml, and its work like a charm!

<dimen name="design_bottom_navigation_active_text_size" tools:override="true">@dimen/design_bottom_navigation_text_size</dimen>
like image 33
Dita Aji Pratama Avatar answered Sep 28 '22 05:09

Dita Aji Pratama