Kamran Akbary
Kamran Akbary

Reputation: 2993

Android, new support lib 25, BottomNavigationView implementation

As support lib ver 25 released, google produced new BottomNavigationView as new API:

android.support.design.widget.BottomNavigationView class implements the bottom navigation pattern from the Material Design spec.

Sadly, this doesn't seem true and there is no real documentation. Apparently, the BottomNavigationView:

  1. Doesn't work as described using xmlns:design="http://schema.android.com/apk/res/android.support.design"
  2. Doesn't support different tab colors or the nice circular reveal color effect
  3. Doesn't offer any coordinator layout behavior for automatic hiding
  4. Doesn't work with snackbars or FAB
  5. Doesn't work with a transparent navigation bar
  6. Doesn't mention for tablets

enter image description here

How can I implement this in the project? And also how to style it to make it actually implement the Bottom Navigation pattern?

Upvotes: 3

Views: 5411

Answers (2)

chetan mekha
chetan mekha

Reputation: 685

It's late reply but below solution will save someone's time.please check below points as well.

  1. Bottomnavigationview support from version 25+.
  2. Update your SDK to latest version.
  3. Set project target sdk version to 25.
  4. Set below configuration in apps build.gradle.

compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:design:25.3.1' compile 'com.android.support:support-vector-drawable:25.3.1'

Upvotes: 1

Velikodniy
Velikodniy

Reputation: 63

Add to your activity

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    ...>

    ...

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:menu="@menu/my_navigation_items" />

    ...

</FrameLayout>

describe menu:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/add"
        android:icon="@android:drawable/ic_menu_add"
        android:title="add" />
    <item
        android:id="@+id/delete"
        android:icon="@android:drawable/ic_menu_delete"
        android:title="delete" />
    <item
        android:id="@+id/call"
        android:icon="@android:drawable/ic_menu_call"
        android:title="call" />
</menu>

and then you can set listeners:

bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        // ...
        return true;
    }
});

You can get more information here: https://developer.android.com/reference/android/support/design/widget/BottomNavigationView.html

Upvotes: 5

Related Questions