Other [new feature] FontAwesome and Material Icons

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
When will be ready the next Rel B4A ?
The beta version is almost ready.

But will be possible set FontAwesome + Text, right ?
Yes. The icons are regular characters. The picker just copies them to the clipboard.
See the tips section at the end of the tutorial.
 

corwin42

Expert
Licensed User
Will it be possible to create Drawables on the fly from the IconFonts so we can use them for ActionItems in the Menu or in the NavigationView (DesignSupport lib) ?
 

Erel

Administrator
Staff member
Licensed User


The icons are regular characters. It is possible to convert them to drawables with:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.AddMenuItem3("Apple", "Test", TextToBitmap(Chr(0xF179), 28), True)
   Activity.AddMenuItem3("Android", "Test", TextToBitmap(Chr(0xF17B), 28), True)
End Sub

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, lblfontAwesome.Typeface, FontSize)
   cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, lblfontAwesome.Typeface, FontSize, Colors.White, "CENTER")
   Return bmp
End Sub
Note that the Chr(0xxxx) comes from the code editor icon picker.
 

Sapta

Member
Licensed User


The icons are regular characters. It is possible to convert them to drawables with:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.AddMenuItem3("Apple", "Test", TextToBitmap(Chr(0xF179), 28), True)
   Activity.AddMenuItem3("Android", "Test", TextToBitmap(Chr(0xF17B), 28), True)
End Sub

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, lblfontAwesome.Typeface, FontSize)
   cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, lblfontAwesome.Typeface, FontSize, Colors.White, "CENTER")
   Return bmp
End Sub
Note that the Chr(0xxxx) comes from the code editor icon picker.

Hi @Erel
According this code, I use in Icon but error
B4X:
NavDrawer.NavigationView.Menu.AddWithGroup2(2, 3, 1000, "Setting", XML.GetDrawable("ic_settings_black_24dp"))
to ..
B4X:
NavDrawer.NavigationView.Menu.AddWithGroup2(2, 3, 1000, "Setting", TextToBitmap(Chr(0xF179), 28))
got error : java.lang.IllegalArgumentException: method de.amberhome.objects.appcompat.ACMenuWrapper.AddWithGroup2 argument 5 has type android.graphics.drawable.Drawable, got android.graphics.Bitmap

What this mean?
Thank you
 

Emme Developer

Well-Known Member
Licensed User
Hi @Erel
According this code, I use in Icon but error
B4X:
NavDrawer.NavigationView.Menu.AddWithGroup2(2, 3, 1000, "Setting", XML.GetDrawable("ic_settings_black_24dp"))
to ..
B4X:
NavDrawer.NavigationView.Menu.AddWithGroup2(2, 3, 1000, "Setting", TextToBitmap(Chr(0xF179), 28))
got error : java.lang.IllegalArgumentException: method de.amberhome.objects.appcompat.ACMenuWrapper.AddWithGroup2 argument 5 has type android.graphics.drawable.Drawable, got android.graphics.Bitmap

What this mean?
Thank you
TextToBitmap return a bitmap, AddWithGroup2 Expect a Drawable

B4X:
Dim bd As BitmapDrawable
    bd.Initialize(TextToBitmap(Chr(0xF179), 28))
    NavDrawer.NavigationView.Menu.AddWithGroup2(2, 3, 1000, "Setting", bd)
 
Status
Not open for further replies.
Top