Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to selected or highlight TextView programmatically in Android?

Currently, I am create a small app for reading. There is a textview to display text. We can bookmark text and store in a listview. I want to click from listview and it highlight or select the bookmark index in the textview. I can get the bookmark_index. Is there method like textview.setSelect(Start,Length)? or Any library can do it? Thank

Please look image view to understand my idea.

enter image description here

like image 751
K.Sopheak Avatar asked Nov 08 '22 03:11

K.Sopheak


1 Answers

Use Spannable

Spannable WordtoSpan = new SpannableString("partial colored text");        
WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), startIndex, stopIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(WordtoSpan);
like image 158
Nitesh Avatar answered Nov 15 '22 05:11

Nitesh