I have a badge on BottomNavigationView
item but it is getting displayed outside the item icon. I want it to overlap the item icon on the top right corner.
Asked
Active
Viewed 311 times
0

aminography
- 21,986
- 13
- 70
- 74

Neelabh Anand
- 71
- 1
- 2
-
Just use this: `yourBottomNav.showBadge(R.id.bottomNavigationClockMenuId).apply { number = 1 }` You can also remove it if you want. – A S M Sayem Sep 24 '19 at 18:09
-
Yes it does show a badge, but i need to know a way to update its position within the menu item if possible. Currently i can set its gravity to the corners of menu item only. – Neelabh Anand Sep 26 '19 at 19:59
-
Well, I have left an answer (solution) regarding your problem. Check if it works or not. If works, make it as the correct answer. Thanks @Neelabh – A S M Sayem Sep 27 '19 at 06:46
2 Answers
0
Visit These Url
show project
https://github.com/axarlotwala/CafeDelear
These Code Work For Bottom Notification badge
BottomNavigationMenuView menuView =
(BottomNavigationMenuView) navigation.getChildAt(0);
View view = menuView.getChildAt(1);
BottomNavigationItemView itemView =
(BottomNavigationItemView) view;
View badge =
LayoutInflater
.from(this)
.inflate(R.layout.notification_badge,itemView,true);
tvCount = badge.findViewById(R.id.tvCount);
tvCount.setText("0");

axar
- 539
- 2
- 17
-
Yes, currently i am using this approach and it works just fine. But instead of inflating a new layout and setting its position, i want to adjust the position of default badge provided by the bottomNavigationView. – Neelabh Anand Sep 26 '19 at 19:58
0
So here is your solution:
This is to create or set a badge to your navigation item :
// 'nav_view' the id of your BottomNavigationView
nav_view.getOrCreateBadge(R.id.navigation_history).number = 10
And this is to set your badge gravity:
nav_view.getOrCreateBadge(R.id.navigation_history).badgeGravity = BadgeDrawable.TOP_START
// you can also use BadgeDrawable.TOP_UP and BadgeDrawable.BOTTOM_END
// as BadgeDrawable.TOP_END is the default gravity.
Hope is helps, Let me know.

A S M Sayem
- 2,010
- 2
- 21
- 28