你需要把
String
中的url路径
src
例如:
String videoPath="http://api.thingspeak.com/channels/31592/charts/1?width=450&height=260&results=60&dynamic=true\\";
String html = "<iframe width=\"450\" height=\"260\" style=\"border: 1px solid #cccccc;\" src=\""+videoPath+" ></iframe>";
如果videoUrl为null或无效,则页面未加载,则需要隐藏webView
以下是代码:
private boolean isValidUrl(String url) {
Pattern p = Patterns.WEB_URL;
Matcher m = p.matcher(url.toLowerCase());
if(m.matches())
return true;
else
return false;
}
然后将其加载到
webView
webview.getSettings().setJavaScriptEnabled(true);
if(videoPath!=null && isValidUrl(videoPath)
{
mWebView.setVisibility(View.VISIBLE);
webview.loadData(html, "text/html", null);
}
else
webview.setVisibility(View.GONE);