views:

252

answers:

2

Hi,

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

+1  A: 

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.

CommonsWare
Thanks! I eventually figured this out myself... cilly me... but it doesn't seem to work. I followed the official Dev guide and implied, for example: str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);Strange...
Rob
You're changing the background color in that code. If you want the text to be invisible, change the text color.
CommonsWare
Right... thanks. I used BackgroundColorSpan instead of ForegroundColorSpan... much obliged.
Rob
A: 

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?

stealthcopter