-
-
Save espritm/3643c1f280d5c1f1a50a0c94a552e3be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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