Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BottomNavigationView text blinking on change

Here is blinking: 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" />

Styles.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>

Selectors nav_bottom_text_selector and nav_bottom_selectorhave the same code.

<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 Here is tab change listener. But I do not think that problem is here because even I comment this part it is anyway blinking.

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;
    }
    });

Navigation menu.xml for bottom navigation view

<?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>
like image 648
goraga1 Avatar asked Feb 02 '18 13:02

goraga1


1 Answers

This issue happens because of an API change introduced in Android Q that affected the transition used to animate the BottomNavigationView menu items. You've got two ways to fix it:

FIRST: Include this dependency in your app's graddle

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

This will replace the library's transition mechanism and the issue will go away.

SECOND: Lower your Target SDK Version to API 28 or lower. Although, I would only recommend this solution if the first one doesn't work, since you would loose any behavioral change introduced in the new version of the OS.

Hope this helps!

like image 147
RodXander Avatar answered Nov 15 '22 01:11

RodXander