gpt4 book ai didi

android - 单击图标时如何禁用底部导航 View 中的动画?

转载 作者:行者123 更新时间:2023-11-29 01:06:03 25 4
gpt4 key购买 nike

我正在为我的应用程序使用默认的 BottomView 导航栏,它有 4 个按钮,它们有一个糟糕的移动动画,而且兼容库中似乎没有方法。禁用它。请帮忙。

P.s 我不想使用第三方底部导航。

最佳答案

//Create a new class Bottom Navigation Bar helper and then implement it in the buttons classes

public class BottomNavigationViewHelper {
@SuppressLint("RestrictedApi")
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);
}
}


//and then just use this code in every button class

protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity);
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavViewBar);
BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
BottomNavigationViewHelper.enableNavigation(mContext, bottomNavigationView);
Menu menu=bottomNavigationView.getMenu();
MenuItem menuItem=menu.getItem(ACTIVITY_NUM);
menuItem.setChecked(true);
}

这将使按钮表现良好。刚接触android,代码不是我写的,希望对你有帮助

关于android - 单击图标时如何禁用底部导航 View 中的动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47109335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com