【问题标题】:BottomNavigationView text blinking on changeBottomNavigationView 文本在更改时闪烁
【发布时间】:2018-02-02 13:32:19
【问题描述】:

这里闪烁: http://gph.is/2GH9P0b

<android.support.design.widget.BottomNavigationView
       android:id="@+id/navigation"
       style="@style/BottomNavigation"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"
       android:layout_marginEnd="0dp"
       android:layout_marginStart="0dp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:menu="@menu/navigation" />

样式.xml

<style name="BottomNavigation">
    <item name="android:background">@color/colorPrimary</item>
    <item name="itemIconTint">@drawable/nav_bottom_selector</item>
    <item name="itemTextColor">@drawable/nav_bottom_text_selector</item>
</style>

选择器 nav_bottom_text_selectornav_bottom_selector 具有相同的代码。

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@android:color/white" android:state_checked="true"/>
    <item android:color="#6e6e6e" />

MainActivity.class 这是选项卡更改监听器。但我认为问题不在这里,因为即使我评论这部分它仍然在闪烁。

navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected (@NonNull MenuItem item) {

        switch (item.getItemId()) {
            case R.id.navigation_exercises:
                // even not replace tabs, just hide and show                          
                fragmentManager.beginTransaction().show(exerciseFragment).hide(workoutFragment).hide(profileFragment).commit();
                SharedPrefsHelper.getInstance().setLastTab(getApplicationContext(), ConsKeys.BOTTOM_TAB_EXERCISE);
                break;
            case R.id.navigation_workouts:
                fragmentManager.beginTransaction().hide(exerciseFragment).show(workoutFragment).hide(profileFragment).commit();
                SharedPrefsHelper.getInstance().setLastTab(getApplicationContext(), ConsKeys.BOTTOM_TAB_WORKOUTS);
                break;

            case R.id.navigation_profile:
                fragmentManager.beginTransaction().hide(exerciseFragment).hide(workoutFragment).show(profileFragment).commit();
                //Saving last tab     
                SharedPrefsHelper.getInstance().setLastTab(getApplicationContext(), ConsKeys.BOTTOM_TAB_PROFILE);


                break;
        }

        return true;
    }
    });

底部导航视图的导航 menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/navigation_exercises"
        android:icon="@drawable/ic_home_black_24dp"
        android:title="@string/title_exercises" />

    <item
        android:id="@+id/navigation_workouts"
        android:icon="@drawable/ic_dashboard_black_24dp"
        android:title="@string/title_workouts" />

    <item
        android:id="@+id/navigation_profile"
        android:icon="@drawable/ic_notifications_black_24dp"
        android:title="@string/title_profile" />

</menu>

【问题讨论】:

  • TextView 的闪烁通常意味着您在不断地重绘它。您可以将您正在设置文本的Activity 中的代码添加到TextView 吗?
  • 你来了,造型很抱歉,我是新来的。
  • 我没有手动设置文本,它会自动更改,来自 menu.xml
  • 现在我看到了你的 gif,我不知道你说的眨眼是什么意思。它看起来像一个正常的涟漪效应。
  • 是的,你是对的,它的连锁反应,我只是检查一下。好的,谢谢你的帮助))

标签: android xml selector drawable android-bottom-nav-view


【解决方案1】:

发生此问题的原因是 Android Q 中引入的 API 更改影响了用于为 BottomNavigationView 菜单项设置动画的过渡。你有两种方法可以解决它:

FIRST:将此依赖项包含在您应用的 graddle 中

implementation 'androidx.transition:transition:1.3.0-rc02'

这将取代图书馆的过渡机制,问题就会消失。

第二次:将您的目标 SDK 版本降低到 API 28 或更低。不过,我只会在第一个不起作用的情况下推荐此解决方案,因为您将失去新版本操作系统中引入的任何行为更改。

希望这会有所帮助!

【讨论】:

  • 这救了我。谢谢!!
  • 这不能解决问题:(
猜你喜欢
  • 2020-02-29
  • 2014-06-25
  • 2015-09-27
  • 1970-01-01
  • 1970-01-01
  • 2017-08-06
  • 2015-02-25
  • 2017-03-08
  • 1970-01-01
相关资源
最近更新 更多