Skip to content

Instantly share code, notes, and snippets.

@espritm
Last active March 28, 2017 09:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
private void M_navigationView_NavigationItemSelected(object sender, NavigationView.NavigationItemSelectedEventArgs e)
{
AddBadgeNotificationToMenuItem(e.MenuItem);
//...
}
private void AddBadgeNotificationToMenuItem(IMenuItem menuItem)
{
TextView textviewBadgeNotif = (TextView)MenuItemCompat.GetActionView(m_navigationView.Menu.FindItem(menuItem.ItemId));
//Red square with rounded corner and white text color
textviewBadgeNotif.SetBackgroundResource(Resource.Drawable.left_menus_itemBadge);
textviewBadgeNotif.SetTextColor(Color.White);
textviewBadgeNotif.Gravity = GravityFlags.Center;
//square size = 25 x 25 dp
FrameLayout.LayoutParams lparams = (FrameLayout.LayoutParams)textviewBadgeNotif.LayoutParameters;
lparams.Height = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 25, Resources.DisplayMetrics);
lparams.Width = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 25, Resources.DisplayMetrics);
textviewBadgeNotif.LayoutParameters = lparams;
//Show or hide badge notification
if (textviewBadgeNotif.Text != "")
{
textviewBadgeNotif.Text = "";
textviewBadgeNotif.Visibility = ViewStates.Gone;
}
else
{
textviewBadgeNotif.Text = "1";
textviewBadgeNotif.Visibility = ViewStates.Visible;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment