Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I scroll a WebView to a specific point on Android

I have a WebView and I would like my app to find a mark on the text(I'm using the symbol ► in the html).I have lots of html files each with almost 10 of these markings.

I have done it pretty easily with TextView doing this:

    int offset=texto.indexOf("SPECIFIC MARKING ON TEXT");   
    final int line = textview.getLayout().getLineForOffset(offset); 
    final int y = textview.getLayout().getLineTop(line); // e.g. 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 do I accomplish that on Webview ? The reason I use Webview is due to better text formatting.

like image 666
theAnquisp Avatar asked Nov 04 '22 07:11

theAnquisp


1 Answers

In fact, it's even simpler with a WebView. You can use the findAll method for the first occurrence, then findNext(true) for the following markers. The view will automatically scroll to the requested text.

like image 88
XMoby Avatar answered Nov 15 '22 00:11

XMoby