Android Question FontAwesome and Material Icons on DSNavigationDrawer [resolved]

Anser

Well-Known Member
Licensed User
I am trying to substitute MSIconicDrawable with the B4A inbuilt support for FontAwsome.

To display FontAwsome Bitmap on DSNavigation drawer, I am trying to use the Sub named TextToBitmap() shared by Erel.

How do I change the color of the Icon/Bitmap created using the Sub TextToBitmap ?. I am trying to place the Icon/Bitmap created using the Sub TextToBitmap() on the DSNavigationDrawer. DSNavigationDrawer expects either a Bitmap or BitmapDrawable to display the Icon on the Drawer.

In the following code, I tried replacing different colors, unfortunately, there seems no difference. Whatever color I use the Bitmap appears in Black color only cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, Typeface.FONTAWESOME, FontSize, Colors.White, "CENTER")
The code doesn't have any effect on the color of the Bitmap/icon.

B4X:
'When using MSIconicDrawable, here I have the option to change the color of the icon
Dim IconHome As MSIconicDrawable  : IconHome.Initialize("gmd_home")  : IconHome.Color = 0xffff4081

'In this case how do I change the color of the icon ? ie TextToBitmap(Chr(0xF0EE), 30)
Dim oBitMap As BitmapDrawable
oBitMap.Initialize(TextToBitmap(Chr(0xF0EE), 30))

NavDrawer.NavigationView.Menu.AddWithGroup2(1, 1, 1, "Home", oBitMap  ).Checked = True
NavDrawer.NavigationView.Menu.AddWithGroup(1, 2, 2, "My Menu", TextToBitmap(Chr(0xF209), 30)  ).Checked = True

Sub TextToBitmap (s As String, FontSize As Float) As Bitmap
   Dim bmp As Bitmap
   bmp.InitializeMutable(32dip, 32dip)
   Dim cvs As Canvas
   cvs.Initialize2(bmp)
   Dim h As Double = cvs.MeasureStringHeight(s, Typeface.FONTAWESOME, FontSize)
   'Tried changing the color in the next line, but no effect on the final image. It is appearing as grey only
   cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, Typeface.FONTAWESOME, FontSize, Colors.White, "CENTER")
   Return bmp
End Sub

Any help will be appreciated.
 

JohnC

Expert
Licensed User
The reply in post #2 allows you to set the icon color for ALL the icons in the menu.

But, I too am interested in how to set the color for each icon separately just like you can do with MSIconicDrawable method in post #1, but that method needs the long-name of the FA or MI icons you want to use, which the icon picker tool doesn't support placing in the clipboard.

Any ideas?
 
Upvote 0

IlCasti

Active Member
Licensed User
The reply in post #2 allows you to set the icon color for ALL the icons in the menu.

But, I too am interested in how to set the color for each icon separately just like you can do with MSIconicDrawable method in post #1, but that method needs the long-name of the FA or MI icons you want to use, which the icon picker tool doesn't support placing in the clipboard.

Any ideas?

You can use this code

B4X:
Dim jo As JavaObject = oBitMap
Dim p As JavaObject
p.InitializeStatic("android.graphics.PorterDuff.Mode")
jo.RunMethod("setColorFilter",Array(0xFF00FF00,p.GetField("SRC_IN")))

as explained here
 
Upvote 0
Top