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");
}
最佳答案
您需要将 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);
关于java - Android 如何在 android iframe webview 中传递 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50390515/