iOS Question SetBadge in BarButton

MarcoRome

Expert
Licensed User
Longtime User
Hi all is possibile set SetBadge in BarButton.

i tried with:

B4X:
Dim b1 As BarButton
b1.InitializeBitmap(KeepOriginalColors(LoadBitmap(File.DirAssets, "cart.png")), "left")
....
badger1.SetBadge(b1, 2)

but the app crash.
Thank you
 

MarcoRome

Expert
Licensed User
Longtime User
Hi Erel
I tried but there are a lot of differences.
Can you give me a hand please.
Thank you

B4X:
..
badge = badge + 1
UpdateIcon("cart", AddBadgeToIcon(cartBitmap, badge))
....


Sub AddBadgeToIcon(bmp As Bitmap, Number As Int) As Bitmap
    Dim cvs As Canvas
    Dim mbmp As Bitmap
    mbmp.InitializeMutable(32dip, 32dip)
    cvs.Initialize2(mbmp)
    Dim target As Rect
    target.Initialize(0, 0, mbmp.Width, mbmp.Height)
    cvs.DrawBitmap(bmp, Null, target)
    If Number > 0 Then
        cvs.DrawCircle(mbmp.Width - 8dip, 8dip, 8dip, Colors.Red, True, 0)
        cvs.DrawText(Min(Number, 9), mbmp.Width - 8dip, 12dip, Typeface.DEFAULT_BOLD, 12, Colors.White, "CENTER")
    End If
    Return mbmp
End Sub

Sub UpdateIcon(MenuTitle As String, Icon As Bitmap)
    Dim m As ACMenuItem = GetMenuItem(MenuTitle)
    m.Icon = BitmapToBitmapDrawable(Icon)
End Sub

Sub BitmapToBitmapDrawable (bitmap As Bitmap) As BitmapDrawable
    Dim bd As BitmapDrawable
    bd.Initialize(bitmap)
    Return bd
End Sub
 
Upvote 0
Top