VsBottomNavigationView - A library for building any BottomNavigationView you want without creating your custom implementation.

Overview

VsBottomNavigationView

A library for building any BottomNavigationView you want without creating your custom implementation.

Gradle

androidExtensions {
    experimental = true //see https://kotlinlang.org/docs/tutorials/android-plugin.html#using-kotlin-android-extensions
}

dependencies {
    implementation 'com.wshtaits:vsbottomnavigationview:1.0.0'
}

Methods

fun setAutoSelectable(isAutoSelectable: Boolean)

fun setItemAnimator(animator: ItemAnimator?)

fun setItemAnimatorForPosition(itemPosition: Int, animator: ItemAnimator)

fun setItemAnimatorForId(@IdRes itemId: Int, animator: ItemAnimator)

fun setOnItemClickAction(action: ((itemId: Int) -> Unit)?)

fun setOnItemSelectAction(action: ((itemId: Int) -> Unit)?)

fun selectItemById(@IdRes itemId: Int)

fun selectItemByPosition(itemPosition: Int)

Simple example

layout/activity_sample.xml

<com.wshtaits.vsbottomnavigationview.VsBottomNavigationView
    android:id="@+id/vs_bottom_navigation_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff"
    android:elevation="8dp"
    app:menu="@menu/sample"
    app:itemLayout="@layout/item_sample" />
    

layout/item_sample.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:background="?selectableItemBackgroundBorderless"
    >

    <ImageView
        android:id="@+id/icon_iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="4dp"
        />

    <TextView
        android:id="@+id/title_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        />

</LinearLayout>

menu/sample.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/action_wifi"
        android:title="@string/wifi"
        android:icon="@drawable/ic_wifi"
        android:checked="true"
        />

    <item
        android:id="@+id/action_cellular"
        android:title="@string/cellular"
        android:icon="@drawable/ic_cellular"
        />

    <item
        android:id="@+id/action_battery"
        android:title="@string/battery"
        android:icon="@drawable/ic_battery"
        />

</menu>

SampleItemAnimator.kt

class SampleItemAnimator(context: Context) : ItemAnimator() {

    private val selectedColor = context.getColor(android.R.color.black)
    private val unselectedColor = context.getColor(android.R.color.darker_gray)

    override fun ItemViewHolder.onCreate(menuItem: MenuItem) {
        icon_iv.background = menuItem.icon
        title_tv.text = menuItem.title

        if (menuItem.isChecked) {
            menuItem.icon.setTint(selectedColor)
            title_tv.setTextColor(selectedColor)
        } else {
            menuItem.icon.setTint(unselectedColor)
            title_tv.setTextColor(unselectedColor)
        }
    }

    override fun ItemViewHolder.onSelect(menuItem: MenuItem) {
        menuItem.icon.setTint(selectedColor)
        title_tv.setTextColor(selectedColor)
    }

    override fun ItemViewHolder.onDeselect(menuItem: MenuItem) {
        menuItem.icon.setTint(unselectedColor)
        title_tv.setTextColor(unselectedColor)
    }
}

SampleActivity.kt

vs_bottom_navigation_view.setItemAnimator(SampleItemAnimator())

Animated example

Just change ItemAnimator implementation to something like this: SampleItemAnimator.kt

Specific item example

Create specific item layout layout/item_sample_specific.xml and separate ItemAnimator for it SpecificSampleItemAnimator.kt.

Then add it inside VsBottomNavigationView tag.

<com.wshtaits.vsbottomnavigationview.VsBottomNavigationView
    android:id="@+id/vs_bottom_navigation_view"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_gravity="bottom"
    android:background="#fff"
    android:elevation="8dp"
    app:menu="@menu/sample"
    app:itemLayout="@layout/item_sample"
    tools:targetApi="lollipop" >

    <include layout="@layout/item_sample_specific" />

</com.wshtaits.vsbottomnavigationview.VsBottomNavigationView>

And in Activity:

vs_bottom_navigation_view.setItemAnimatorForId(R.id.action_battery, SpecificSampleItemAnimator(this))

Note:

  • layout_menuPosition corresponds to a menu item at a specified position.
  • Root view id of your specific item layout become menu item id.
  • If you use <include> tag then layout_menuPosition attribute must be specified where you specified other layout_* attributes.

isAutoSelectable

If you want to handle the event first, and only then decide whether to make it selected then set isAutoSelectable attribute to false through xml or code and use setOnItemClickAction and selectItemBy* methods.

License

Copyright (c) 2019 Shtaits Valeriy.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You might also like...
Alligator is a modern Android navigation library that will help to organize your navigation code in clean and testable way.

Alligator Alligator is a modern Android navigation library that will help to organize your navigation code in clean and testable way. Features Any app

React Native lets you customize the navigation bar for Android.
React Native lets you customize the navigation bar for Android.

react-native-system-navigation-bar React Native lets you customize the navigation bar for Android. Hide Lean Back Immersive Sticky Immersive Low Profi

Dismiss your keyboard by tapping anywhere outside it.
Dismiss your keyboard by tapping anywhere outside it.

Keyboard Dismisser What is this? Keyboard Dismisser is a simple library that allows you to dismiss keyboard by tapping anywhere outside it. Currently

Navigation Component: THE BEST WAY to create navigation flows for your app
Navigation Component: THE BEST WAY to create navigation flows for your app

LIVE #017 - Navigation Component: A MELHOR FORMA de criar fluxos de navegação para o seu app! Código fonte do projeto criado na live #017, ensinando c

Xdimen - Support multiple screen sizes easily by scaling your dimensions
Xdimen - Support multiple screen sizes easily by scaling your dimensions

Support multiple screen sizes easily by scaling your dimensions. How does Xdimen work? When you have a UI design with a specific dimension, and

🎉 [Android Library] A light-weight library to easily make beautiful Navigation Bar with ton of 🎨 customization option.
🎉 [Android Library] A light-weight library to easily make beautiful Navigation Bar with ton of 🎨 customization option.

Bubble Navigation 🎉 A light-weight library to easily make beautiful Navigation Bars with a ton of 🎨 customization options. Demos FloatingTopBarActiv

Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

An efficient TabLayout library implemented with RecyclerView.
An efficient TabLayout library implemented with RecyclerView.

RecyclerTabLayout An efficient TabLayout library implemented with RecyclerView. Features Efficient when having many tabs Easy setup with ViewPager (sa

An Android library for managing multiple stacks of fragments
An Android library for managing multiple stacks of fragments

FragNav Android library for managing multiple stacks of fragments (e.g., Bottom Navigation , Navigation Drawer). This library does NOT include the UI

Owner
Valeriy Shtaits
Valeriy Shtaits
Why would I want to fitsSystemWindows?

Why would I want to fitsSystemWindows?

Seachal 3 Jan 4, 2022
DSC Moi University session on using Navigation components to simplify creating navigation flow in our apps to use best practices recommended by the Google Android Team

Navigation Components Navigate between destination using safe args How to use the navigation graph and editor How send data between destinations Demo

Breens Mbaka 6 Feb 3, 2022
Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps

Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps. The extension provides handy methods and properties to change the behaviour as well as the appearance of the navigation bar.

Zain Ul Hassan 4 Nov 30, 2022
NTabLayout is a simple tab bar custom view under android which has click-sliding and scaling up animation effect.

NTabLayout Brief NTabLayout is a simple tab bar custom view under android which has click-sliding and scaling up animation effect. This tab bar's effe

XellossRyan 1 Oct 22, 2021
CustomNavigationDrawer - Custom Navigation Drawer with compose

An easy sample to explore navigation component and navigation drawer from Jetpac

rafael altamirano 0 Jan 4, 2022
A lightweight library to help you navigate in compose with well typed functions.

TypedNavigation A lightweight library to help you navigate in compose with well typed functions. Installation: You can add this library to your projec

xmartlabs 23 Apr 7, 2022
A library that you can use for bottom navigation bar. Written with Jetpack Compose

FancyBottomNavigationBar A library that you can use for bottom navigation bar. W

Alperen Çevlik 3 Jul 27, 2022
Android Library for making animated tutorials inside your app

##SlidingTutorial Cleveroad introduces Sliding Tutorial Library for Android Hey guys, hope you haven’t started developing a tutorial for your Android

Cleveroad 2.5k Dec 31, 2022
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.

MaterialDrawer ... the flexible, easy to use, all in one drawer library for your Android project. What's included ?? • Setup ??️ • Migration Guide ??

Mike Penz 11.6k Dec 27, 2022
A flexible, easy to use, unique drawer library for your Android project.

Duo Navigation Drawer This Android library provides an easy way to create an alternative navigation drawer for android. Instead of a drawer that slide

PSD 1.1k Dec 21, 2022