Android的web视图锚链接(跳转链接)无法正常工作锚链、跳转、视图、无法正常

2023-09-12 06:33:11 作者:嫑冭

我在我的Andr​​oid应用程序一个的WebView正在加载使用loadDataWithBaseURL()方法的HTML字符串。问题是,当地的锚链接(< A HREF =#链接> ...)无法正常工作。当链接被点击,而是会突出显示,但不滚动到相应的锚。

如果我使用的WebView的使用loadURL()方法加载一个包含锚链接页面时,也不起作用。不过,如果我在浏览器中加载相同的URL,锚链接做的工作。

有没有得到这些工作的web视图所需要的任何特殊处理?

我使用的API V4(1.6)。

没有太多的code,这里有一些测试code,我一直在与相关部分:

 的WebView detailBody =(web视图)findViewById(R.id.article_detail_body);
字符串s =&LT;一href=\"#link\">LINK!</a><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><a NAME = \链接\&GT;&LT; / A&GT;测试!;
detailBody.loadDataWithBaseURL(API.HomeURL(本),S,text / html的,UTF-8,);
 

解决方案

它看起来像问题是,我有一个滚动型中的web视图。当这样的配置的的WebView不能滚动到一个锚链接。重构我的布局,消除了滚动型后,锚链接正常工作。

Android比iPhone网页浏览速度快52

I have a WebView in my Android App that is loading an HTML string using the loadDataWithBaseURL() method. The problem is that local anchor links (<a href="#link">...) are not working correctly. When the link is clicked, it becomes highlighted, but does not scroll to the corresponding anchor.

This also does not work if I use the WebView's loadUrl() method to load a page that contains anchor links. However, if I load the same URL in the browser, the anchor links do work.

Is there any special handling required to get these to work for a WebView?

I am using API v4 (1.6).

There isn't much to the code, here are the relevant parts of some test code I've been working with:

WebView detailBody = (WebView) findViewById(R.id.article_detail_body);
String s = "<a href=\"#link\">LINK!</a><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><a name=\"link\"></a>Testing!";
detailBody.loadDataWithBaseURL(API.HomeURL(this), s, "text/html", "utf-8", "");

解决方案

It looks like the problem is that I had a WebView within a ScrollView. The WebView isn't able to scroll to an anchor link when configured like this. After refactoring my layout to eliminate the ScrollView, the anchor links work correctly.