0

I can select and highlight some words in TextView (when it selectable) with long press on word, but I want to make it without touch.

So how can I select and highlight text in code itself or programattically ?

KishuDroid
  • 5,411
  • 4
  • 30
  • 47

2 Answers2

0

If you want the link effect you can put the <u></u> on your text in the strings.xml file.

Check this answer for more info: https://stackoverflow.com/a/10019093/3465623

Community
  • 1
  • 1
luiscosta
  • 855
  • 1
  • 10
  • 16
0

Of course you can do it in your code by using SpannableString.

Here is the answer of your question.

    SpannableString ss1 = new SpannableString(s);
    ss1.setSpan(new RelativeSizeSpan(1.1f), 0, 6, 0); // set size and give character posiotion which you want to higlight
    ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 6, 0); // Color of highlighting your code.
    textview.setText(ss1);

Take a look at this link which will shows you more use of SpannableString.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47