Skip to content

Instantly share code, notes, and snippets.

@AgiMaulana
Created August 16, 2017 18:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AgiMaulana/e63a870e7719d010f22b25d8f8c76fd6 to your computer and use it in GitHub Desktop.
Save AgiMaulana/e63a870e7719d010f22b25d8f8c76fd6 to your computer and use it in GitHub Desktop.
Adding badge (such as notification count) in bottom nav menu item on android
navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(this);
navigation.setSelectedItemId(R.id.navigation_store);
BottomNavigationMenuView bottomNavigationMenuView =
(BottomNavigationMenuView) navigation.getChildAt(0);
View v = bottomNavigationMenuView.getChildAt(2); // number of menu from left
new QBadgeView(this).bindTarget(v).setBadgeNumber(5);
/**
* compile 'q.rorbin:badgeview:1.1.2'
* https://github.com/qstumn/BadgeView
*/
@anooshkhalid
Copy link

Hello,
I tried this but it returning the getChildAt(x) as null and I couldn't access the child view.

@AgiMaulana
Copy link
Author

@anooshkhalid make sure the child number is no out of index

@eugenio-caicedo
Copy link

Excellent solution. It is not the ideal solution but it is working correctly. Thanks @AgiMaulana

@mohamedhamada1
Copy link

in case more than 3 bottom navigation items, when you press menu item will shift in that case number is far away icon

@AgiMaulana
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment