AHBottomNavigation


Source link: https://github.com/aurelhubert/ahbottomnavigation

AHBottomNavigation

Library to implement the Bottom Navigation component from Material Design guidelines (minSdkVersion=14).

Demo

What's new (2.1.0) - Changelog

  • Update libraries versions
  • Add enable/disable tab state (with custom color)
  • Add new xml attributes ( colored, accentColor, inactiveColor, disableColor, coloredActive, coloredInactive)
  • Add param notificationAnimationDuration
  • Update getDrawable method with AppCompatResources.getDrawable(context, drawableRes); If you use drawable selector and target API < 21, don't forget to add this: AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); ?

Features

  • Follow the bottom navigation guidelines ( https://www.google.com/design/spec/components/bottom-navigation.html)
  • Add 3 to 5 items (with title, icon & color)
  • Choose your style: Classic or colored navigation
  • Add a OnTabSelectedListener to detect tab selection
  • Support icon font color with "setForceTint(true)"
  • Manage notififcations for each item
  • Enable/disable tab state

How to?

Gradle

dependencies {

  compile 'com.aurelhubert:ahbottomnavigation:2.1.0' 
}

XML

<com.aurelhubert.ahbottomnavigation.AHBottomNavigation

android:id="@+id/bottom_navigation"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

OR

<android.support.design.widget.CoordinatorLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

...

<com.aurelhubert.ahbottomnavigation.AHBottomNavigation

android:id="@+id/bottom_navigation"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="bottom" />  </android.support.design.widget.CoordinatorLayout>

Activity/Fragment

AHBottomNavigation bottomNavigation = (AHBottomNavigation) findViewById(R.id.bottom_navigation);
  // Create items AHBottomNavigationItem item1 = new AHBottomNavigationItem(R.string.tab_1, R.drawable.ic_maps_place, R.color.color_tab_1);
 AHBottomNavigationItem item2 = new AHBottomNavigationItem(R.string.tab_2, R.drawable.ic_maps_local_bar, R.color.color_tab_2);
 AHBottomNavigationItem item3 = new AHBottomNavigationItem(R.string.tab_3, R.drawable.ic_maps_local_restaurant, R.color.color_tab_3);
  // Add items bottomNavigation.addItem(item1);
 bottomNavigation.addItem(item2);
 bottomNavigation.addItem(item3);
  // Set background color bottomNavigation.setDefaultBackgroundColor(Color.parseColor("#FEFEFE"));
  // Disable the translation inside the CoordinatorLayout bottomNavigation.setBehaviorTranslationEnabled(false);
  // Enable the translation of the FloatingActionButton bottomNavigation.manageFloatingActionButtonBehavior(floatingActionButton);
  // 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);
  // Display color under navigation bar (API 21+) // Don't forget these lines in your style-v21 // <item name="android:windowTranslucentNavigation">true</item> // <item name="android:fitsSystemWindows">true</item> bottomNavigation.setTranslucentNavigationEnabled(true);
  // Manage titles bottomNavigation.setTitleState(AHBottomNavigation.TitleState.SHOW_WHEN_ACTIVE);
 bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
 bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_HIDE);
  // 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 or remove notification for each item bottomNavigation.setNotification("1", 3);
 // OR AHNotification notification = new AHNotification.Builder()
  .setText("1")
  .setBackgroundColor(ContextCompat.getColor(DemoActivity.this, R.color.color_notification_back))
  .setTextColor(ContextCompat.getColor(DemoActivity.this, R.color.color_notification_text))

.build();
 bottomNavigation.setNotification(notification, 1);
  // Enable / disable item & set disable color bottomNavigation.enableItemAtPosition(2);
 bottomNavigation.disableItemAtPosition(2);
 bottomNavigation.setItemDisableColor(Color.parseColor("#3A000000"));
  // Set listeners bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
  @Override  public boolean onTabSelected(int position, boolean wasSelected) {

// Do something cool here...

return true;  
}
 
}
);
 bottomNavigation.setOnNavigationPositionListener(new AHBottomNavigation.OnNavigationPositionListener() {
  @Override public void onPositionChange(int y) {

// Manage the new y position  
}
 
}
);

With XML menu

int[] tabColors = getApplicationContext().getResources().getIntArray(R.array.tab_colors);
 AHBottomNavigation bottomNavigation = (AHBottomNavigation) findViewById(R.id.bottom_navigation);
 AHBottomNavigationAdapter navigationAdapter = new AHBottomNavigationAdapter(this, R.menu.bottom_navigation_menu_3);
 navigationAdapter.setupWithBottomNavigation(bottomNavigation, tabColors);

TODO

  • Manage tablet

Contributions

Feel free to create issues / pull requests.

License

AHBottomNavigation library for Android Copyright (c) 2017 Aurelien Hubert (http://github.com/aurelhubert).  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. 

Resources

RecyclerView snapping example with SnapHelper.

This tool generates an Android Parcelable implementation based on fields in the class.

IntelliJ IDEA / Android Studio plugin with some tools and usability improvements.

Android Studio / Eclipse ADT template for including icon resources from androidicons.com in your project.

Material Theme for IDEA & Android Studio.

Plugin to navigate between events posted by EventBus.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes