Android Question Font Awesome with < Android 8

madru

Active Member
Licensed User
Longtime User
Hi,

I am struggling to get Font Awesome working on devices with Android 7 and downwards
a customer of mine complained that his backup tablet with Android 7 does not show the 'correct' icons, just a crossed out rectangle, same APK does run on his main device (Android 10)

I was able to reproduce the behaviour on Android 7. Loading the font does also not help, the correct icon is not displayed

B4X:
Private mTf As Typeface
mTf = Typeface.LoadFromAssets("fontawesome-webfont.ttf")
'mi = B4XPages.AddMenuItem(Me, cs.Initialize.Typeface(Typeface.FONTAWESOME).Size(20).Append(Constants.EditChar).PopAll)
mi = B4XPages.AddMenuItem(Me, cs.Initialize.Typeface(Typeface.FONTAWESOME).Typeface(mTf).Size(20).Append(Constants.EditChar).PopAll)

I must do something wrong but I can't figure it out .....
 

Mahares

Expert
Licensed User
Longtime User
I must do something wrong but I can't figure it out .
Take a look at this thread. It may reveal why you are not getting the Fontawesome to work for you. If not, export your project and someone with a similar OS in question can probably help:
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi Mahares,

I am aware of that tread.....

tiny example project attached
 

Attachments

  • FontAwesome.zip
    10.1 KB · Views: 127
Upvote 0

Mahares

Expert
Licensed User
Longtime User
tiny example project attached
The below code will work for you: I changed the word: MATERIALICONS to FONTAWESOME
B4X:
mi = B4XPages.AddMenuItem(Me, cs.Initialize.Append("some text ").Typeface(Typeface.FONTAWESOME).Append(Chr(0xf044)).PopAll)
 
Upvote 0

Rubsanpe

Active Member
Licensed User
I also tried to run Erel's example on the B4xPages in a 5.1 device and the result is the one below with the icons.

Screenshot_2020-11-13-15-51-22.png
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Take a look at this thread. It may reveal why you are not getting the Fontawesome to work for you. If not, export your project and someone with a similar OS in question can probably help:

oops, copied the wrong code into the test app.

correct code uses FONTAWESOME, but doesn't work.
 
Upvote 0

Biswajit

Active Member
Licensed User
Longtime User
Try to add the Designer Support Library to your project. If it does not work then try to add this to your project,
B4X:
#AdditionalJar: com.android.support:support-v4
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
but doesn't work.
Since mi is a customtype, I think you need to write: mi.Title. See code below. It works for me now on a device with OS 5.1
B4X:
Dim mi As B4AMenuItem
    mi.Title = B4XPages.AddMenuItem(Me, cs.Initialize.Append("some text ").Typeface(Typeface.FONTAWESOME).Append(Chr(0xf044)).PopAll)
 
Upvote 0

Rubsanpe

Active Member
Licensed User
Hi. I tried with "mi.Title" and indeed the strange symbol no longer appears instead of the icon, but neither does the icon appear in the bar. The icons are placed in the menu although the option "mi.AddToBar = true"

Rubén
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
mmh, will not work if a theme is set. Using e.g the example from the Forum breaks it.

What has to be changed to make it work, .... empty CreateResource breaks it already

THX



B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.




SetApplicationAttribute(android:theme, "@style/LightTheme")

CreateResource(values, colors.xml,
<resources>
    <color name="actionbar">#ff0000FF</color>
    <color name="statusbar">#ff0000FF</color>
    <color name="textColorPrimary">#ffffffff</color>
    <color name="navigationBar">#ff0000FF</color>
</resources>
)
CreateResource(values-v20, theme.xml,
<resources>
    <style name="LightTheme" parent="@android:style/Theme.Material.Light">
        <item name="android:colorPrimary">@color/actionbar</item>
        <item name="android:colorPrimaryDark">@color/statusbar</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:navigationBarColor">@color/navigationBar</item>
        <item name="android:colorAccent">@color/navigationBar</item>
        <item name="android:alertDialogTheme">@style/AlertDialogCustom</item>
    </style>

    <style name="AlertDialogCustom" parent="@android:style/Theme.Material.Light.Dialog.Alert">
      <item name="android:colorPrimary">@color/actionbar</item>
      <item name="android:colorAccent">@color/navigationBar</item>
    </style>
</resources>
)
CreateResource(values-v14, theme.xml,
<resources>
    <style name="LightTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
    </style>
    <style name="CustomActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/actionbar</item>
    </style>
</resources>
)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the updated LightTheme code:
B4X:
CreateResource(values-v20, theme.xml,
<resources>
    <style
        name="LightTheme" parent="@android:style/Theme.Material.Light">
       <item name="android:actionMenuTextAppearance">@style/LowerCaseMenu</item>
    </style>
     <style name="LowerCaseMenu" parent="android:TextAppearance.Material.Widget.ActionBar.Menu">
        <item name="android:textAllCaps">false</item>
    </style>
</resources>
)
 
Upvote 0
Top