I have anchor links (example: <a href="#P12"/>
) in my HTML which I load into a WebView and this WebView is inside a NestedScrollView. When I temporarily disable the NestedScrollView because everyone advises doing that when anchor links are not working properly, these anchor links work perfectly. However, my layout does need this NestedScrollView because of multiple reasons:
- It has a CollapsingToolbarLayout and
app:layout_behavior="@string/appbar_scrolling_view_behavior
needs to be set; - There are layout elements above and below the WebView;
- These elements have to scroll together as a whole.
The expected behaviour is that the content jumps to the correct part of the web page when an anchor link is clicked. The actual behaviour is that the content jumps to some random place and that you can no longer scroll through the entire page (either the top or bottom is cut off).
Is there a possibility to make these anchor links work inside my WebView that is inside a NestedScrollView?
On StackOverflow I have found one question that is similar to this one, but unfortunately it has no answers and it is from 2017 so I highly doubt anyone will answer it soon.