Home » Android » java – Google BottomNavigationView item title disappears after few rapid tab switch

java – Google BottomNavigationView item title disappears after few rapid tab switch

Posted by: admin May 14, 2020 Leave a comment

Questions:

activity_main.xml:

 <android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:elevation="4dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0"
    />

bottom_bar.xml:

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

<item
    android:id="@+id/tab_addcard"
    android:enabled="true"
    android:title="@string/addcard"
    android:icon="@drawable/ic_tabicon_addcard"
    app:showAsAction="ifRoom|withText"/>
<item
    android:id="@+id/tab_approvals"
    android:enabled="true"
    android:title="@string/approvals"
    android:icon="@drawable/ic_tabicon_approvals"
    app:showAsAction="always|withText"/>
<item
    android:id="@+id/tab_mycard"
    android:enabled="true"
    android:title="@string/mycard"
    android:icon="@drawable/ic_tabicon_mycard"
    app:showAsAction="always|withText"/>

MainActivity.java:

BottomNavigationView bottombar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bottombar= (BottomNavigationView) findViewById(R.id.bottom_navigation);

    bottombar.inflateMenu(R.menu.bottom_bar);
}

My question is: After I finish everything from initialization of bottom bar to adding items in it. Once I run it and try rapidly (very fast) switching between item tabs of BottomNavigationView suddenly in-between item title text disappears. Can anybody suggest me any solution?

How to&Answers:

setOnNavigationItemSelectedListener should return false instead of true

Answer:

In my case i was using Co-ordinator layout in one of the fragments and had android:fitSystemWindows="true"

changed it to false.. fixed my problem. 🙂