我用anchor link加载html内容时,在webview中遇到一些奇怪的问题。
以下代码对于 anchor标签可以很好的执行,但是只能执行一次。
当我再次点击 anchor标签时,就不能执行。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mywebview);
String html = "<html><body><p><a href='#C4'>See also Chapter 4</a></p><p><h2>Chapter 1</h2><p>This chapter explains ba bla bla</p><h2>Chapter 2</h2><p>This chapter explains ba bla bla</p><h2>Chapter 3</h2><p>This chapter explains ba bla bla</p><h2><a name='C4'>Chapter 4</a></h2><p>This chapter explains ba bla bla</p><h2>Chapter 5</h2><p>This chapter explains ba bla bla</p><h2>Chapter 6</h2><p>This chapter explains ba bla bla</p><h2>Chapter 7</h2><p>This chapter explains ba bla bla</p><h2>Chapter 8</h2><p>This chapter explains ba bla bla</p><h2>Chapter 9</h2><p>This chapter explains ba bla bla</p></body></html>";
String mime = "text/html";
String encoding = "utf-8";
WebView myWebView = (WebView)this.findViewById(R.id.webView1);
myWebView.loadDataWithBaseURL(null, html, mime, encoding, null);
}
我在不同的设备装置中测试代码。
可以执行:
1. Samsung S Plus --> 2.3.4
2. Samsung Galaxy Y --> 2.3.6
3. Samsung Galaxy Tab --> 2.3.3
4. Motorola Xoom --> 3.2
不能执行:
1. LG Optimus --> 2.2
2. DELL XCD35(ZTE Blade) --> 2.2
3. HTC WildFire --> 2.2.1
这是操作系统的问题还是别的问题? 如何解决呢?