如何在没有 Helper 的情况下删除 BottomNavigationView 的所有动画?

How to remove all animation of BottomNavigationView without Helper?

如何在没有任何 Helper 或 proGuard 的情况下删除 BottomNavigationView 的所有动画,并且使用 google material 依赖项 com.google.android.material:material:1.0.0

  1. 我们都知道默认情况下 BottomNavigationView 具有多种效果,例如选择菜单项时水平翻译和更大的文本。

  1. 我们可以删除添加的翻译
<com.google.android.material.bottomnavigation.BottomNavigationView
    ...
    app:itemHorizontalTranslationEnabled="false"/>

  1. 不用app:itemHorizontalTranslationEnabled="false"这种方式我们可以一起显示标签和删除翻译
<com.google.android.material.bottomnavigation.BottomNavigationView
    ...
    app:labelVisibilityMode="labeled"/>

  1. 如果我们对数字 3 不满意,我们仍然可以通过在 dimens.xml 中添加 dimens 来使用与非活动菜单相同的文本大小。通过这样做,我们几乎没有 BottomNavigationView
  2. 的动画
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <dimen name="design_bottom_navigation_active_text_size"
        tools:override="true">12sp</dimen>
</resources>

奖金问题

但是,还有一个问题。如果菜单文本是长文本怎么办?如果它是由 2 个单词组成的呢?

如果这是您的问题,您会看到在选择菜单时修剪过的长文本。 (请看第三个菜单)

这是我尝试BottomNavigationView

后得到的解决方案
void selectFragment(MenuItem item) {
    item.setChecked(true);

    int itemID = item.getItemId();
    if (itemID == R.id.menu_a) {
        pushFragment(MenuAFragment.newInstance("MENU A"));
    }
    else if (itemID == R.id.menu_b) {
        pushFragment(MenuAFragment.newInstance("MENU B"));
    }
    else if (itemID == R.id.menu_c) {
        pushFragment(MenuAFragment.newInstance("MENU C"));
    }
    else if (itemID == R.id.menu_d) {
        pushFragment(MenuAFragment.newInstance("MENU D"));
    }
    else {
        pushFragment(MenuAFragment.newInstance("MENU E"));
    }

    /**** START FROM HERE ****/

    TextView largeTextView = bottomNavigationView.findViewById(itemID)
            .findViewById(com.google.android.material.R.id.largeLabel);
    TextView smallTextView = bottomNavigationView.findViewById(itemID)
            .findViewById(com.google.android.material.R.id.smallLabel);

    smallTextView.setVisibility(View.VISIBLE);
    largeTextView.setVisibility(View.GONE);
}

基本上,我们只需要隐藏 largeTextView 并显示 smallTextView

想了解更多?看看这个 repo DisableShiftMode