Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust background to text on TextView in android

I'd like to know if anyone could help me with this.

I've got a textView and I want the background just to be applied to the text, according to its size, not to the whole textView.

There is no problem when the text is only one row lenghth, but there is when it takes more than one line...

Maybe this pic helps to understand this all...

top: what I have bottom: what I want

alt text

Thank you :-)

like image 335
Aitor Gómez Avatar asked Nov 30 '10 11:11

Aitor Gómez


1 Answers

Try using something like this:

TextView tv = (TextView) findViewById(R.id.myid);
tv.setText(Html.fromHtml("<span style="background: red;">Text</span>"));

It might resolve your issue...

EDIT:

I found the solution here : Set color of TextView span in Android using SpannableString

like image 87
Mikpa Avatar answered Nov 12 '22 02:11

Mikpa