
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
com.github.afflya:afflyasnavigation-kotlin
Advanced tools
Kotlin Android library for implementing the behavior of navigation elements upon content scrolling
AfflyasNavigation is an Android library for implementing the behavior of navigation components upon content scrolling

ToolbarANBottomNavigationANBottomNavigationSnackbar appearsAdd the following line to your build.gradle's dependencies section:
implementation 'com.github.afflya:afflyasnavigation-kotlin:1.1.0'
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.afflyas.sample.MainActivity"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
<com.afflyas.afflyasnavigation.ANTopBar
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
app:behaviorTranslationEnabled="true"
android:background="@color/colorPrimary"
android:theme="@style/AppTheme.AppBarOverlay">
<!--Add content to your top bar here. For example, add a toolbar-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.afflyas.afflyasnavigation.ANTopBar>
<com.afflyas.afflyasnavigation.ANFloatingActionButton
android:id="@+id/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:srcCompat="@drawable/ic_audiotrack_black_24dp"
app:useCompatPadding="true"
app:withANBottomNavigation="true"/>
<com.afflyas.afflyasnavigation.ANBottomNavigation
android:id="@+id/botNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behaviorTranslationEnabled="true"
app:colored="true"
app:titleState="always_show"
app:itemsMenu="@xml/bot_nav_menu"
android:layout_gravity="bottom"/>
<!--Layout to avoid translucent navigation bar and display cutout on the sides-->
<com.afflyas.afflyasnavigation.ANVerticalContentContainer
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--Space before content to avoid status bar and display cutout-->
<com.afflyas.afflyasnavigation.ANSpaceTop
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:topBarHeightMode="default_action_bar"/>
<!--Place your content here-->
<!--Space after the content to avoid navigation and display cutout-->
<com.afflyas.afflyasnavigation.ANSpaceBottom
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:withANBottomNavigation="true"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</com.afflyas.afflyasnavigation.ANVerticalContentContainer>
</android.support.design.widget.CoordinatorLayout>
// Create items
val item1 = ANBottomNavigationItem(R.string.home, R.drawable.ic_home, R.color.colorPrimary)
val item2 = ANBottomNavigationItem(R.string.chat, R.drawable.ic_chat, R.color.colorAccent)
val item3 = ANBottomNavigationItem(R.string.dashboard, R.drawable.ic_dashboard, R.color.colorPrimaryDark)
val item4 = ANBottomNavigationItem(R.string.music, R.drawable.ic_audiotrack, android.R.color.holo_red_light)
val item5 = ANBottomNavigationItem(R.string.settings, R.drawable.ic_settings, android.R.color.holo_green_light)
// Add items
bottomNavigation.addItem(item1)
bottomNavigation.addItem(item2)
bottomNavigation.addItem(item3)
bottomNavigation.addItem(item4)
bottomNavigation.addItem(item5)
// Set background color
bottomNavigation.setDefaultBackgroundColor(Color.parseColor("#FEFEFE"));
// Enable the translation inside the CoordinatorLayout
bottomNavigation.setBehaviorTranslationEnabled(true);
// Manage titles
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.SHOW_WHEN_ACTIVE);
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_HIDE);
// Change colors
bottomNavigation.setAccentColor(Color.parseColor("#F63D2B"));
bottomNavigation.setInactiveColor(Color.parseColor("#747474"));
// Force to tint the drawable (useful for font with icon for example)
bottomNavigation.setForceTint(true);
// Use colored navigation with circle reveal effect
bottomNavigation.setColored(true);
// Set current item programmatically
bottomNavigation.setCurrentItem(1);
// Customize notification (title, background, typeface)
bottomNavigation.setNotificationBackgroundColor(Color.parseColor("#F63D2B"));
// Add notification for each item
bottomNavigation.setNotification("1", 3);
// OR
val notification = ANNotification.Builder()
.setText("1")
.setBackgroundColor(ContextCompat.getColor(this, R.color.color_notification_back))
.setTextColor(ContextCompat.getColor(this, R.color.color_notification_text))
.build()
bottomNavigation.setNotification(notification, 1)
// Remove notification for each item
bottomNavigation.setNotification("", 3);
// Enable / disable item & set disable color
bottomNavigation.enableItemAtPosition(2);
bottomNavigation.disableItemAtPosition(2);
bottomNavigation.setItemDisableColor(Color.parseColor("#3A000000"));
// Set listener
bottomNavigation.setOnTabSelectedListener(object : ANBottomNavigation.OnTabSelectedListener {
override fun onTabSelected(position: Int, wasSelected: Boolean): Boolean {
when(position){
1 -> {
bottomNavigation.setNotification("", 1)
bottomNavigation.setNotification(" ", 2)
}
2 -> {
bottomNavigation.setNotification("22", 1)
bottomNavigation.setNotification("", 2)
}
}
return true
}
})
res/xml like this<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:title="@string/home"
android:icon="@drawable/ic_home_black_24dp"
android:color="@color/colorPrimary"/>
<item
android:title="@string/chat"
android:icon="@drawable/ic_chat_black_24dp"
android:color="@color/colorAccent"/>
<item
android:title="@string/dashboard"
android:icon="@drawable/ic_dashboard_black_24dp"
android:color="@color/colorPrimaryDark"/>
<item
android:title="@string/music"
android:icon="@drawable/ic_audiotrack_black_24dp"
android:color="@android:color/holo_red_light"/>
<item
android:title="@string/settings"
android:icon="@drawable/ic_settings_black_24dp"
android:color="@android:color/holo_green_light"/>
</menu>
app:itemsMenu="@xml/bot_nav_menu" attribute with the path to the file to your ANBottomNavigationThe elements automatically adapt to transparent bars, you just need to include these lines in your application's theme
<style name="AppTheme.TranslucentNavigation" parent="AppTheme">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
styles-v21 if your minSdkVersion<21Copyright (c) 2018 Andrey Poznyakov (https://github.com/Afflya).
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.
FAQs
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.