How to scroll WebView to a specific point on Android

I have a WebView and I would like my application to detect a label in the text (I use the β–Ί symbol in html). I have many html files, each of which contains almost 10 such marks.

I pretty easily did this with a TextView:

int offset=texto.indexOf("SPECIFIC MARKING ON TEXT"); final int line = textview.getLayout().getLineForOffset(offset); final int y = textview.getLayout().getLineTop(line); // eg I want to scroll to line final ScrollView s = (ScrollView)findViewById(R.id.ScrollView01); s.post(new Runnable() { @Override public void run() { s.smoothScrollTo(0, y); } }); 

But how to do it in Webview? The reason I use Webview is due to better text formatting.

+4
source share
1 answer

In fact, it is even simpler with WebView. You can use the findAll method for the first entry, then findNext (true) for the following markers. The view will automatically scroll through the required text.

+2
source

Source: https://habr.com/ru/post/1391944/


All Articles