Find text in a EditText Android

2019-09-14 03:02发布

I know there is this question How to find text in android through a SearchView or EditText? but its not answering my question properly. I have an EditText in which there will be text. I want to find all the text occurences and highlight it like the Ctrl + F in Google Chrome (Windows). Also, there will be a button like "Find Next". I got a image to tell what I want.

What I want

Got the image from How to find text in android through a SearchView or EditText?

I want all the specific text to be highlighted in yellow and the current text to be highlighted in read. Like the image above.

1条回答
等我变得足够好
2楼-- · 2019-09-14 03:12

i think you can use this code. It should work perfectly for your case, the only difference is that instead of the foreach clause, you will have to use an int

int i = *numberOfRecurrences*;
int index = *recurrenceShown*;

than you can add the next button and foreach click doing

index++;

and than change the background of index recurrences and setting back the color of other recurrences to the default one.

if you have questions ask :)

查看更多
登录 后发表回答