如何在Android中以编程方式选择或突出显示TextView? [英] How to selected or highlight TextView programmatically in Android?

查看:112
本文介绍了如何在Android中以编程方式选择或突出显示TextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在创建一个用于阅读的小应用程序.有一个textview可以显示文本.我们可以为文本添加书签并存储在列表视图中.我想从列表视图中单击,它会高亮显示或选择文本视图中的书签索引.我可以得到bookmark_index.有像textview.setSelect(Start,Length)这样的方法吗?或任何图书馆都可以做到?谢谢

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.

推荐答案

使用Spannable

Use Spannable

Spannable WordtoSpan = new SpannableString("partial colored text");        
WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), startIndex, stopIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(WordtoSpan);

这篇关于如何在Android中以编程方式选择或突出显示TextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆