badgerduke
badgerduke

Reputation: 1013

adding transparent/watermarked text over another layout

I am writing a simple application with one main layout. The application has a state which users can toggle. If the state is "on", I want see-through (watermarked, although I know this can have a different meaning) text to overlay the main layout. I am guessing I would have to define a second layout to lay over the main layout. Or maybe not. If I'm not totally crazy, I would appreciate any guidance. Thanks.

Upvotes: 1

Views: 1625

Answers (1)

FoamyGuy
FoamyGuy

Reputation: 46856

You should'nt need to create another layout. Just put a TextView in your main layout and use this to change its transparency

int alpha = 100;
mTxt.setTextColor(Color.argb(alpha, 0, 0, 0));

alpha can be anything 0-255, 0 being transparent and 255 being 100% solid. You can also change the 0,0,0 to a different RGB value if you don't want black text.

You can also set the alpha from xml if you want (Which you should do unless you need to change it at run time):

<TextView
...
...
android:background="#55000000" />

in this instance the first two digits represent the alpha value (55 in the example), they can be between 00 and FF. The next 6 digits are the RGB value in hex.

Upvotes: 1

Related Questions