0

How can I create this Bottomnavigationview? I used AHBottomNavigation to create this view successfully and added FloatingActionButton to view with the bottom margin. But I think it is not true to add margin to fix FloatingActionButton position. I want to hide bottom navigation and FloatingActionButton in some situations like Recyclerview scrolled.enter image description here

Behrooz Fard
  • 536
  • 4
  • 26

1 Answers1

-1
 <android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="?android:attr/windowBackground"
    android:foreground="?attr/selectableItemBackground"
    app:itemBackground="@color/background"
    app:itemIconTint="@android:color/holo_green_dark"
    app:itemTextColor="@android:color/black"
    app:menu="@menu/more_nav"/>

use this code in your java class

BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

    // attaching bottom sheet behaviour - hide / show on scroll
    CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) navigation.getLayoutParams();
    layoutParams.setBehavior(new BottomNavigationBehavior());
    }
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
        = new BottomNavigationView.OnNavigationItemSelectedListener() {

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        Fragment fragment;
        switch (item.getItemId()) {
            case R.id.inbox:
                getSupportActionBar().setTitle("Inbox");
                fragment = new OneFragment();
                loadFragment(fragment);
                return true;
            case R.id.terms:
                getSupportActionBar().setTitle("Terms");
                fragment = new TwoFragment();
                loadFragment(fragment);
                return true;
            case R.id.upgrade:
                getSupportActionBar().setTitle("Upgrade Plan");
                fragment = new ThreeFragment();
                loadFragment(fragment);
                return true;
           case R.id.bot:
               getSupportActionBar().setTitle("Buyfie Chatbot");
               fragment = new FourFragment();
               loadFragment(fragment);
               return true;
        }

        return false;
    }
};
private void loadFragment(Fragment fragment) {
    // load fragment
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.frame_container, fragment);
    transaction.addToBackStack(null);
    transaction.commit();
}

use this in your main activity

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />