/// <summary> /// The ApplyBadge. /// </summary> /// <param name="bottomNavigationView">The bottomNavigationView<see cref="BottomNavigationItemView"/>.</param> /// <param name="color">The color<see cref="XColor"/>.</param> /// <param name="text">The text<see cref="string"/>.</param> /// <param name="textColor">The textColor<see cref="XColor"/>.</param> public static void ApplyBadge(this BottomNavigationItemView bottomNavigationView, XColor color, string text, XColor textColor) { if (!bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Any()) { bottomNavigationView.SetClipChildren(false); bottomNavigationView.SetClipToPadding(false); ImageView imageView = bottomNavigationView.GetChildrenOfType <ImageView>().Single(); bottomNavigationView.RemoveView(imageView); FrameLayout badgeContainerFrameLayout = new FrameLayout(bottomNavigationView.Context) { LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent) { Gravity = GravityFlags.CenterHorizontal } }; badgeContainerFrameLayout.AddView(imageView); BadgeFrameLayout badgeContainer = CreateBadgeContainer(bottomNavigationView.Context); badgeContainer.TopMargin = 20; badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible; badgeContainer.Background = CreateBadgeBackground(bottomNavigationView.Context, color); badgeContainer.AddView(CreateBadgeText(bottomNavigationView.Context, text, textColor)); badgeContainerFrameLayout.AddView(badgeContainer); bottomNavigationView.AddView(badgeContainerFrameLayout); } else { BadgeFrameLayout badgeContainer = bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Single(); badgeContainer.TopMargin = 20; badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible; ((PaintDrawable)badgeContainer.Background).Paint.Color = color.IsDefault ? XColor.FromRgb(255, 59, 48).ToAndroid() : color.ToAndroid(); TextView textView = (TextView)badgeContainer.GetChildAt(0); textView.Text = text; textView.SetTextColor(textColor.IsDefault ? XColor.White.ToAndroid() : textColor.ToAndroid()); textView.SetTextSize(ComplexUnitType.Sp, 10); } }
/// <summary> /// The ApplyTinyBadge. /// </summary> /// <param name="bottomNavigationView">The bottomNavigationView<see cref="BottomNavigationItemView"/>.</param> /// <param name="textColor">The textColor<see cref="XColor"/>.</param> public static void ApplyTinyBadge(this BottomNavigationItemView bottomNavigationView, XColor textColor) { if (!bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Any()) { bottomNavigationView.SetClipChildren(false); bottomNavigationView.SetClipToPadding(false); ImageView imageView = bottomNavigationView.GetChildrenOfType <ImageView>().Single(); bottomNavigationView.RemoveView(imageView); FrameLayout badgeContainerFrameLayout = new FrameLayout(bottomNavigationView.Context) { LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent) { Gravity = GravityFlags.CenterHorizontal } }; badgeContainerFrameLayout.AddView(imageView); BadgeFrameLayout badgeContainer = CreateBadgeContainer(bottomNavigationView.Context); badgeContainer.TopMargin = 24; badgeContainer.Visibility = ViewStates.Visible; badgeContainer.Background = CreateBadgeBackground(bottomNavigationView.Context, XColor.Transparent); badgeContainer.AddView(CreateBadgeText(bottomNavigationView.Context, "●", textColor, 20)); badgeContainerFrameLayout.AddView(badgeContainer); bottomNavigationView.AddView(badgeContainerFrameLayout); } else { BadgeFrameLayout badgeContainer = bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Single(); badgeContainer.TopMargin = 24; badgeContainer.Visibility = ViewStates.Visible; ((PaintDrawable)badgeContainer.Background).Paint.Color = XColor.Transparent.ToAndroid(); TextView textView = (TextView)badgeContainer.GetChildAt(0); textView.Text = "●"; textView.SetTextSize(ComplexUnitType.Sp, 20); textView.SetTextColor(textColor.ToAndroid()); } }
public static void ApplyBadge(this TabLayout.TabView tabView, XColor color, string text, XColor textColor) { if (!tabView.GetChildrenOfType <BadgeFrameLayout>().Any()) { tabView.SetClipChildren(false); tabView.SetClipToPadding(false); TextView tabTextView = tabView.GetChildrenOfType <TextView>().Single(); tabView.RemoveView(tabTextView); FrameLayout badgeContainerFrameLayout = new FrameLayout(tabView.Context) { LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent) }; badgeContainerFrameLayout.AddView(tabTextView); BadgeFrameLayout badgeContainer = CreateBadgeContainer(tabView.Context); badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible; badgeContainer.Background = CreateBadgeBackground(tabView.Context, color); badgeContainer.AddView(CreateBadgeText(tabView.Context, text, textColor)); badgeContainerFrameLayout.AddView(badgeContainer); tabView.AddView(badgeContainerFrameLayout); } else { BadgeFrameLayout badgeContainer = tabView.GetChildrenOfType <BadgeFrameLayout>().Single(); badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible; ((PaintDrawable)badgeContainer.Background).Paint.Color = color.IsDefault ? XColor.FromRgb(255, 59, 48).ToAndroid() : color.ToAndroid(); TextView textView = (TextView)badgeContainer.GetChildAt(0); textView.Text = text; textView.SetTextColor(textColor.IsDefault ? XColor.White.ToAndroid() : textColor.ToAndroid()); } }