Search code examples
androidandroid-fragmentsbottomnavigationview

BottomNavigationView reduce size after click an BottomNavView item?


When I click on bottom nav item, BottomNavigationView size automatically reduce. It only happen when control transfer from home item to any other item. When I click on any other item third time, it's automatically back up to it's original size.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

 BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav_view);
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                Fragment selectedFragment = null;


                switch (menuItem.getItemId()){
                    case R.id.home_bottom_nav:
                        selectedFragment = new HomeFragment();
                        break;
                    case R.id.game_bottom_nav:
                        selectedFragment = new GameFragment();
//                        selectedFragment = GameFragment.newInstance("Para1","Para2");
                        break;
                    case R.id.even_bottom_nav:
                        selectedFragment = new EventFragment();
                        break;
                    case R.id.profile_bottom_nav:
                        selectedFragment = new ProfileFragment();
                        break;
                }

                assert selectedFragment != null;
                getSupportFragmentManager().beginTransaction().replace(R.id.fragmentLayout,selectedFragment)
                        .commit();

                return true;
            }
        });

        getSupportFragmentManager().beginTransaction().replace(R.id.fragmentLayout,new HomeFragment()).commit();

XML code

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".HomeActivity">

    <FrameLayout
        android:id="@+id/fragmentLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/bottom_nav_view"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_nav_view"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="?android:attr/windowBackground"
        app:itemTextAppearanceActive="@style/Widget.BottomNavigationView"
        app:labelVisibilityMode="labeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_nav_items" />

</android.support.constraint.ConstraintLayout>

enter image description here

enter image description here

enter image description here


Solution

  • Try this

    <android.support.design.widget.BottomNavigationView
            android:id="@+id/bottom_nav_view"
            android:layout_width="0dp"
            android:layout_height="56dp"
            android:background="?android:attr/windowBackground"
            app:itemTextAppearanceActive="@style/Widget.BottomNavigationView"
            app:labelVisibilityMode="labeled"
            app:menu="@menu/bottom_nav_items"
    
            app:itemHorizontalTranslationEnabled="false"
            app:itemTextAppearanceInactive="@style/Widget.BottomNavigationView"
    
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
     />