0

I m trying to set background color text view to length of the text in that text view , if I use textView.SetBackground() then it will set background color to whole textview , i dont want this , I want backgorund color only for Text of that Textview... Thanks in advance...

laalto
  • 150,114
  • 66
  • 286
  • 303
ADT
  • 255
  • 1
  • 4
  • 14

4 Answers4

0

Set the TextView's layout_width to wrap_content, then the background will only be as lasrge as the content.

alex
  • 6,359
  • 1
  • 23
  • 21
0

use SpannableString class

here is example

String btnText = btn.getText();
SpannableString spannableSummary = new SpannableString(btnText);
spannableSummary.setSpan(new ForegroundColorSpan(0xff6083f0), 0, summary.length(), 0);

btn.setText(btnText);
erkasraim
  • 11
  • 2
0

You can use :

textView.setTextColor();

To set text colour for your text view.

Vipul Purohit
  • 9,807
  • 6
  • 53
  • 76
0

You can use

String text = "This is <font color='blue'>blue</font>. This is <font color='red'>red</font>.";
textView.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);