B4J Tutorial [ABMaterial] New: add badge to NavigationBar top items icon (2.51)

Top items WITH an icon in the NavigationBar can show a little 'ios' badge with e.g. a number of unread messages.
Note: you can only start using them AFTER page.FinishedLoading!

Example:

upload_2017-2-9_15-58-6.png


Code (where 'Emails' is the return name of the top button):

Adding/Setting the badge:
B4X:
page.NavigationBar.SetTopBarBadgeOnIcon("Emails", "5",ABM.ICONBADGE_POSITION_TOPRIGHT, ABM.COLOR_RED, ABM.INTENSITY_NORMAL, ABM.COLOR_WHITE, ABM.INTENSITY_NORMAL, ABM.COLOR_WHITE, ABM.INTENSITY_NORMAL)
You can rerun the .SetTopBarBadgeOnIcon() method, e.g. if the number has changed. I did it like this, so you can also change its color too depending on the value.

Removing the Badge:
B4X:
page.NavigationBar.HideTopBarBadgeOnIcon("Emails")
 
Top