【发布时间】:2019-08-13 14:45:25
【问题描述】:
我在 android 应用程序的布局文件中有一个 webview,我想在其中加载一个包含 html 和 javascript 的视频。我想用来加载视频的 html 字符串是:
video= '<div id="15518031408206776"><script type="text/JavaScript" src="https://www.aparat.com/embed/gJ8jm?data[rnddiv]=15518031408206776&data[responsive]=yes"></script></div>'
WebView xml 代码为:
<WebView
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginTop="30dp"
tools:ignore="WebViewLayout"
android:id="@+id/post_video" />
我还在 webview 中启用了 javascriop:
post_video.getSettings().setJavaScriptEnabled(true)
post_video.loadDataWithBaseURL( null, video, "text/html", "UTF-8", null );
但 webview 只显示纯文本 html 代码而不是视频!
you can see the result in this screenshot
我该如何解决这个问题?
更新:
我通过使用 Html.fromHtml(video) 来解码我的 html 字符串解决了这个问题!现在它正在工作,WebView 显示视频。
【问题讨论】:
标签: java android html xml webview