Pawel
Pawel

Reputation: 189

BottomNavigationView with activities

I am using BottomNavigationViewEx (BottomNavigationView with really good features). I have layout and now I want to 'connect' this navigation with my Activities. Usually it's connect with Fragments but my all activities extends AppCompatActivity.

Here's my nav.xml

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.activity.RecipesActivity">

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/navigation_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
        android:id="@+id/navigation_view"
        android:layout_width="0dp"
        android:layout_height="65dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:background="@color/colorPrimary"
        app:itemIconTint="@color/draw_item"
        app:itemTextColor="@color/draw_item"
        app:menu="@menu/nav_items" />

</android.support.constraint.ConstraintLayout>

How can I make this navigation visible on all activities and setup Click Listeners on items? I have five items on my navigation and I want to show for example activity 1 when I click on item 1 and so on.

Upvotes: 1

Views: 798

Answers (1)

Mike
Mike

Reputation: 2705

I would recommend using Fragments for switching between tabs. Few pros when using Fragments:

  • It will prevent from destroying and creation of the activities and screen blinking.
  • It is easier to hold only one BottomNavigationView.
  • Single Responsibility for handling navigation, saving and restoring states.

Upvotes: 1

Related Questions