private void AddTabBadge(int tabIndex) { var element = Element.Children[tabIndex]; var tabbedContentPage = (BadgedContentPage)element; var view = tabLayout?.GetTabAt(tabIndex).CustomView ?? tabStrip?.GetChildAt(tabIndex); var badgeView = (view as ViewGroup)?.FindChildOfType <Badge>(); if (badgeView == null) { var imageView = (view as ViewGroup)?.FindChildOfType <ImageView>(); var badgeTarget = imageView?.Drawable != null ? (Android.Views.View)imageView : (view as ViewGroup)?.FindChildOfType <TextView>(); badgeView = new Badge(Context, badgeTarget); } BadgeViews[element] = badgeView; var badgeText = tabbedContentPage.BadgeText; badgeView.Text = badgeText; element.PropertyChanged += OnTabbedPagePropertyChanged; }
private void AddTabBadge(int tabIndex) { var element = Element.Children[tabIndex]; var view = _tabLayout?.GetTabAt(tabIndex).CustomView ?? _tabStrip?.GetChildAt(tabIndex); var badgeView = (view as ViewGroup)?.FindChildOfType <BadgeView>(); if (badgeView == null) { var imageView = (view as ViewGroup)?.FindChildOfType <ImageView>(); var badgeTarget = imageView?.Drawable != null ? (Android.Views.View)imageView : (view as ViewGroup)?.FindChildOfType <TextView>(); // Create badge for tab badgeView = new BadgeView(Context, badgeTarget); } BadgeViews[element] = badgeView; // Get text var badgeText = CustomTabbedPage.GetBadgeText(element); badgeView.Text = badgeText; // Set color if not default var tabColor = CustomTabbedPage.GetBadgeColor(element); if (tabColor != Xamarin.Forms.Color.Default) { badgeView.BadgeColor = tabColor.ToAndroid(); } element.PropertyChanged += OnTabbedPagePropertyChanged; }