如何以编程方式查找文本?

How find text programmatically?

有没有办法以编程方式查找文本? 我想在TextView或其他方式中放置大量文本,然后搜索特定单词,就像您使用Ctrl + F一样。我没有找到信息,我找到了SearchView但是这些搜索数据只是一个View,没有? 提前致谢。

您可以在算法中使用字符串 class 提供的方法 .contains "Returns true if and only if this string contains the specified sequence of char values" (Oracle Docs) 搜索文本,然后根据该方法 returns 执行的内容如果 CharSequence 存在或不存在,某些代码可以执行您想要的操作。

String Class (Oracle)