[英]Android how to pass url in android iframe webview?
Android如何在android iframe
webview
傳遞url? 我正在嘗試動態地傳遞url服務器,所以我做的
if(ResponseProduct.video!=null) {
String html = "<iframe width=\"450\" height=\"260\" src=\""+ResponseProduct.video+"\" ></iframe>";
WebView webView = (WebView) view.findViewById(R.id.video);
webView.setVisibility(View.VISIBLE);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.setWebChromeClient(new WebChromeClient());
webView.setHorizontalScrollBarEnabled(false);
webView.loadData(html, "text/html; video/mpeg", "UTF-8");
}
你需要在src
放置String
url路徑,如:
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.