Android Question Wrong MaterialIcons ?

D

Deleted member 103

Guest
Hi,

B4X:
Msgbox2("Die Datei wird gelöscht!", "Sind Sie sicher?", "Ja", "Nein","", TextToBitmap(Chr(0xE002), lblMaterialIcons, 26, Colors.White) )
The upper code should show this.
iconpicker.JPG


In my app but this is displayed, what can be wrong here?

msgbox.png
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Works fine here. Tested with this code:
B4X:
Sub Activity_Click
   Msgbox2("asdasd", "asdasdasd", "ok", "", "", TextToBitmap(Chr(0xE002), 20))
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, Typeface.MATERIALICONS, FontSize)
   cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, Typeface.MATERIALICONS, FontSize, Colors.White, "CENTER")
   Return bmp
End Sub
 
Upvote 0
D

Deleted member 103

Guest
Funny, in a different app works the code correctly, and not in this. :(

The SDK in the Manifest is the same.
B4X:
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22"/>

To this day I have had no problems with the code.
 
Upvote 0
D

Deleted member 103

Guest
Test it with the code I posted.
Ok, my mistake! :(
I had swapped MATERIALICONS with FONTAWESOME. ;)
For this I have now improved the code. ;)
B4X:
Public Sub TextToBitmap (s As String, IsMaterialIcons As Boolean, FontSize As Float, color As Int) As Bitmap
    Dim bmp As Bitmap
    bmp.InitializeMutable(32dip, 32dip)
    Dim cvs As Canvas
    cvs.Initialize2(bmp)
    Dim h As Double
    If IsMaterialIcons Then
        h = cvs.MeasureStringHeight(s, Typeface.MATERIALICONS, FontSize)
        cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, Typeface.MATERIALICONS, FontSize, color, "CENTER")
    Else
        h = cvs.MeasureStringHeight(s, Typeface.FONTAWESOME, FontSize)
        cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, Typeface.FONTAWESOME, FontSize, color, "CENTER")
    End If
    Return bmp
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Slightly better:
B4X:
Public Sub TextToBitmap (s As String, IsMaterialIcons As Boolean, FontSize As Float, color As Int) As Bitmap
   Dim bmp As Bitmap
   bmp.InitializeMutable(32dip, 32dip)
   Dim cvs As Canvas
   cvs.Initialize2(bmp)
   Dim h As Double
   Dim t As Typeface
   If IsMaterialIcons Then t = Typeface.MATERIALICONS Else t = Typeface.FONTAWESOME
   h = cvs.MeasureStringHeight(s, t, FontSize)
   cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, t, FontSize, color, "CENTER")
   Return bmp
End Sub
 
Upvote 0
Top