Android Question textColor not working on special characters?

Dave O

Well-Known Member
Licensed User
Longtime User
Hi all,

I have a label where I've set the textColor to red. (This is a poker app, so I display the card as "10 ♥".)

The "10" part is red, but the heart stays black, whether I set it in the designer or using run-time code.

I'm thinking this is because the heart is a special character in the font.

But I'm also thinking it should render in the specified color.

FYI, I'm using the DEFAULT font (which I assume is Roboto). It turns out that the Material Icons and FontAwesome fonts don't have card suits, but the normal font does.

Any help appreciated!
 

DonManfred

Expert
Licensed User
Longtime User
use charsequenebuilder so build the text using normal fonts for the card suits
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
Thanks for the tip, but I still couldn't get it to work with this code:

B4X:
Dim cs As CSBuilder
player1Card1.Text = cs.Initialize.Color(Colors.Red).Append("10 ♥").PopAll
player1Card2.Text = cs.Initialize.Color(Colors.Red).Append("10 " & Chr(9829)).PopAll

I think it may have something to do with the special character, which doesn't show up when I do a Roboto preview on a webpage. Perhaps it's reverting to another font and thereby going back to the default color of black?

I'll try a few more font variations to see. If nothing works, I'll use a graphic instead of trying to use a font character.
 
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
Your code works fine in the emulator. Both the "10" and the Heart symbol are red.

FontAwesome does have a heart symbol. From the Designer click on the label and select FontAwesomeIcons and click on the "..." and search for "heart" and it will show up. But neither font has the other icons for the suits: clubs, spades, diamonds which I find is very odd. I'd recommend use a bitmap for the suit and be done with it. CSBuilder can load bitmaps as in:

B4X:
Dim cs As CSBuilder
cs.Initialize.Size(30).Typeface(Typeface.MONOSPACE)
cs.Append("B4A: ").Image(LoadBitmap(File.DirAssets, "b4a.png"), 40dip, 40dip, False).Append(CRLF)

Then you can control the color and size without any problem. It should work well for you.
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
I just tried my code in an emulator and you're right, the heart symbol is red (as it should be).

My Samsung devices show a black heart, so I suspect it's something to do with their font handling that differs from stock Android.

And it seems to have the same result with both plain strings and CSBuilder, so it doesn't appear to be a CharSequence thing.

Thanks!
 
Upvote 0
Top