How to remove icon animation for bottom navigation

2020-01-30 03:51发布

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.

10条回答
家丑人穷心不美
2楼-- · 2020-01-30 04:18

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>
查看更多
Lonely孤独者°
3楼-- · 2020-01-30 04:22

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);
查看更多
我想做一个坏孩纸
4楼-- · 2020-01-30 04:26

Material Design is getting more handy to use.

App dependency to your Gradle file (Update to the latest version).

implementation 'com.google.android.material:material:1.1.0-alpha09'

In MainActivity, just need to call the clearAnimation() function to the BottomNavigationView class

BottomNavigationView navView = findViewById(R.id.nav_view);
navView.clearAnimation();
查看更多
看我几分像从前
5楼-- · 2020-01-30 04:33

To remove animation or shift move create an bottomNavigationViewHelper class using bottomNavigationViewEX

package com.example.chitchat.utils;
import android.util.Log;
import com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx;

public class BottomNavigationViewHelper {
    private static final String TAG = "bottomNavigationViewHel";

    public static void setupBottomnavigationView(BottomNavigationViewEx bottomNavigationViewEx)
    {
        Log.d(TAG, "setupBottomnavigationView: setting up bottom navigation view");

        bottomNavigationViewEx.enableAnimation(false);
        bottomNavigationViewEx.enableShiftingMode(false);
        bottomNavigationViewEx.enableItemShiftingMode(false);
        bottomNavigationViewEx.setTextVisibility(false);
    }
}
查看更多
做自己的国王
6楼-- · 2020-01-30 04:36

This may not be the most elegant or practical solution but you could try to add the following line to your BottomNavigationView.

app:labelVisibilityMode="unlabeled"

It will remove the label and also disable the animation.

查看更多
冷血范
7楼-- · 2020-01-30 04:36

Try this is the layout

app:labelVisibilityMode="labeled"

or in code level mNavigationView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);

And update your design support library to 28.0.+

查看更多
登录 后发表回答