My HTML is very simple and it should be rendered like this
However android webview loses some of the content and renders it like this
The line that is causing the problem is this
<a name="_ftnref1" href="#_ftn1">[1]</a>
How do I tweak HTML or the webview so that everything is rendered correctly?
MainActivity.kt
import android.os.Bundle
import android.webkit.WebView
class MainActivity : AppCompatActivity() {
val html = """
<!DOCTYPE html>
<html>
<head></head>
<body>
<ul>
<li>content above link</li>
<li>The link is on this line
<a name="_ftnref1" href="#_ftn1">[1]</a>
</li>
<li>content below link</li>
</ul>
<p>
<a name="_ftn1" href="#_ftnref1">[1]</a> Link landing
</p>
</body>
</html>
""".trimIndent()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<WebView>(R.id.web_view).loadData(html, "text/html", "UTF-8")
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…