问题描述
我已在项目中的设计支持库25中实现了底部导航视图。我在视图中有5个图标。每当选择一个图标时,它就会有一些动画。但是当3个或更少的图标没有显示任何动画时。我想删除该动画,只需要对图标进行一些颜色更改。我怎样才能做到这一点?做了足够的谷歌搜索,但找不到解决方案。请帮忙。谢谢。
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.
推荐答案
从这里得到答案。
删除动画或班次模式。
<$ c $的实施c> BottomNavigationView 有条件:当有超过3项时,则使用shift模式。
Implementation of BottomNavigationView
has condition: when there is more than 3 items then use shift mode.
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);
}
}
}
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_bar);
BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
这篇关于如何在android中删除底部导航视图的图标动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!