Android Question Label with Materil Icon AND Text, or alternative

anciaes

Member
Licensed User
Hello!

First, let me say that I'm very impressed by B4A *and* by the community. The software is great (I installed it 5 days ago and already have my app working, even with the roadbumps that someone that starts using a new software needs to overcome), and the community is very helpful and responsive.

Now, my question (I already searched the forum and Google and couldn't find an answer): my main screen has several buttons. In each one, I want an icon (I've used Material Icons) and a text. As far as I could find in the forum, you can't combine two fonts in the same button (and Material Icons are, in fact, a font), so I've created TWO button for each function, put one stacked over the other, painted them in the same color, and put the icon in one of them and the text in the other. Visually, it's a single button, but functionally, there are two of them (with the same command, so that's fine).

All was fine, until I changed the color for the "longpress" or "click" to visually improve the app. Now, if I press one of them, only that one changes color (obviously). I tried to change the color of the other button programatically, but there's a small delay to the change, and it's possible to see they are two buttons and not one. The same applies if the person just mantains the button pressed - you can see a line separating both buttons.

Do you have a suggestion to solve the problem? It can be a way of putting both the icon and the text in the same button, or for both buttons to change color at the same time when pressed / longpressed. I can live with the dividing line... I know I could just put an image inside the button (with both the icon and the text), but I'm trying to avoid that,

Thanks!
 

anciaes

Member
Licensed User
Thank you, Erel! I couldn't find this post when I searched for it, sorry!

I've used the code from the post (including the scaling addition to make the icon larger than the text) and everything worked, with one strange exception: the uppercase letters and symbols are displayed, but any lowercase letter or number is not. Example: If I pass "ABCabc123DEF" to the subroutine, I get "ABC DEF" on the cell phone screen.

The log shows the ASCII codes correctly for every character. I've tried to comment out almost everything on the subroutine and left only the part below (so it is not doing anything other than create the RichString), and even then the lowercase letters and numbers were not printed on the screen:

B4X:
    BTAtualiza.Text = CombineTextWithMaterialIcons(Chr(0xE86A) & CRLF & CRLF & "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890 !@#$%¨&*()",2)

B4X:
Sub CombineTextWithMaterialIcons(s As String, AIconRelsize As Float) As RichString
    Dim rs As RichString
    rs.Initialize(s)
    Return rs
End Sub

With the above code, I got this on the cell phone screen:

(MaterialIcon for RELOAD)


ABCDEFGHIJKLMNOPQRSTUVWXYZ


!@#$%¨&*()

As I said, the ASCII codes are correctly logged (even for the lowercase letters and for the numbers).

Any ideas?

Thanks!
 
Upvote 0

anciaes

Member
Licensed User
Hello, Erel! I've used exactly your code. The code above was just a test, where I removed the FOR loop to see if the problem was with the commands it was executing. It wasn't - with only the snippet above, the problem occurred.

The problem may be the typeface in BTAtualiza. I'll take a look when I get home and get back to you.

As always, thank you for being so responsive!
 
Upvote 0

anciaes

Member
Licensed User
Thanks again! It worked - I had the typeface wrongly set despite your clear warning in the tutorial. Sorry, my bad!

Anyway, I'm glad that you are planning to include it in the new version in a simpler way!
 
Upvote 0
Top