protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Fixed); // Create your application here _bottomBar = BottomBar.AttachShy(FindViewById <CoordinatorLayout>(Resource.Id.myCoordinator), FindViewById(Resource.Id.myScrollingContent), savedInstanceState); _bottomBar.UseFixedMode(); _bottomBar.UseDarkThemeWithAlpha(); _bottomBar.SetItems(new [] { new BottomBarTab(Resource.Drawable.ic_recents, "Recents"), new BottomBarTab(Resource.Drawable.ic_favorites, "Favorites"), new BottomBarTab(Resource.Drawable.ic_nearby, "Nearby") }); _badge0 = _bottomBar.MakeBadgeForTabAt(0, Color.Green, 100); _badge0.AutoShowAfterUnSelection = true; _badge1 = _bottomBar.MakeBadgeForTabAt(1, Color.Green, 100); _badge1.AutoShowAfterUnSelection = true; _badge1.Position = BottomNavigationBar.Enums.BadgePosition.Left; _badge2 = new CustomBottomBarBadge(this, 2, Color.Green); _badge2.Count = 100; _bottomBar.MakeBadgeForTab(_badge2); _bottomBar.SetOnTabClickListener(this); _bottomBar.SetActiveTabColor(Color.Red); }
/// <summary> /// Creates or updates a badge for a page /// </summary> /// <param name="page"></param> void CreateOrUpdateBadgeForPage(Page page) { var pageIndex = Element.Children.IndexOf(page); var badgeCount = BottomBarPageExtensions.GetBadgeCount(page); BottomBarBadge badge; // We'll have to keep track of our badges, otherwise we can't update // and removing + inserting again gives a crappy user experience if (_badges.ContainsKey(page)) { badge = _badges[page]; } else { // Don't need to create a badge when there's no badge to show if (badgeCount == 0) { return; } // BottomBarBadge does not allow us to set color after init. You could, but you'd have to // do it manually because the circle background logic is hidden from us var badgeColor = BottomBarPageExtensions.GetBadgeColor(page); badge = _bottomBar.MakeBadgeForTabAt(pageIndex, badgeColor.ToAndroid(), badgeCount); _badges.Add(page, badge); } // Let's assume that if the new badge count is zero the // default behavior will be to hide the badge if (badgeCount == 0) { badge.Hide(); } else { badge.Count = badgeCount; badge.Show(); } }