Rob
Rob

Reputation: 15253

Android, make portions of text invisible in TextView

I suspect that adding a certain letter/character to the beginning of my text will solve an alignment problem I am currently facing. Needless to say that I do not wish for this letter to appear.
Is there a way to tell a portion of the text to be invisible/transparent?
I reviewed the Spannable interface could not find anything related to visibility.

Thanks, Rob

Upvotes: 1

Views: 2632

Answers (2)

stealthcopter
stealthcopter

Reputation: 14206

You can set invividual colors in a TextView, try looking at this example of multiple colours used in text from anddev. The colour codes are given as ARGB, so you can define the alpha; you would simple use alpha = 0 to make completely transparent. I.E. #00FF0000 would give invisible red text.

I assume you have already tried using android:paddingLeft="1dip" or similar?

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1007584

I suspect that adding a certain letter/character to the beginning of my text will solve an alignment problem I am currently facing.

It is unrealistic for this technique to work for all screen sizes, all screen densities, and all font sizes.

Is there a way to tell a portion of the text to be invisible/transparent?

You can tell a portion of the text to have the same color as the background, assuming you know what your background color is.

Upvotes: 1

Related Questions