Experimenting with the B4XPages example Menu Badges:
www.b4x.com
How can I get the menu items closer together?
This is my amended code sofar from that example:
[B4X] [B4XPages] Menu badges
This is a B4i + B4A example. It adds a dynamic badge to the menu icon. It also shows how to update menu items at runtime. Don't miss: 1. B4A - theme settings in manifest editor. 2. B4i - theme settings in main module. Both are not really needed for this example but are useful.
How can I get the menu items closer together?
This is my amended code sofar from that example:
B4X:
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Dim cs As CSBuilder
cs.Initialize.Color(Colors.Black).Size(16).Append("Menu Icons").PopAll
Root = Root1
'B4XPages.SetTitle(Me, "Menu Icons")
B4XPages.SetTitle(Me, cs)
Root.LoadLayout("MainPage")
'CartBitmap = xui.LoadBitmap(File.DirAssets, "cart.png")
CartBitmap = TextToB4XBitmap(Chr(0xE854),28,Colors.Black,28,28,Typeface.MATERIALICONS,"CENTER")
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 28dip, 28dip)
IconCanvas.Initialize(p)
UpdateMenuItems
End Sub
Sub TextToB4XBitmap(strText As String, fFontSize As Float, iFontColour As Int, _
iWidth As Int, iHeight As Int, _
TF As Typeface, strAlignment As String) As B4XBitmap
Dim bmp As Bitmap
Dim cvs As Canvas
bmp.InitializeMutable(iWidth * 100dip / 100, iHeight * 100dip / 100)
cvs.Initialize2(bmp)
Dim h As Double = cvs.MeasureStringHeight(strText, TF, fFontSize)
cvs.DrawText(strText, bmp.Width / 2, bmp.Height / 2 + h / 2, TF, fFontSize, iFontColour, strAlignment)
Return bmp.As(B4XBitmap)
End Sub
Private Sub UpdateMenuItems
Dim bmp As B4XBitmap = CreateIconWithBadge(CartBitmap, BadgeNumber)
#if B4A
Dim menus As List = B4XPages.GetManager.GetPageInfoFromRoot(Root).Parent.MenuItems
menus.Clear
'add menu items
Dim mi As B4AMenuItem = B4XPages.AddMenuItem(Me, "cart")
mi.AddToBar = True
mi.Bitmap = bmp
Dim b4xbmp As B4XBitmap = TextToB4XBitmap(Chr(0xF142),24,Colors.Black,24,24,Typeface.FONTAWESOME,"CENTER")
Dim mi As B4AMenuItem = B4XPages.AddMenuItem(Me, "hamburger")
mi.AddToBar = True
mi.Bitmap = b4xbmp
Dim ctxt As JavaObject
ctxt.InitializeContext
ctxt.RunMethod("invalidateOptionsMenu", Null)
#else if B4i
Dim bb As BarButton
bb.InitializeBitmap(Main.KeepOriginalColors(bmp), "cart")
B4XPages.GetNativeParent(Me).TopRightButtons = Array(bb)
#end if
End Sub
[CODE]
RBS