java - Android 如何在 android iframe webview 中传递 url?

标签 java 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");

                        } 

最佳答案

您需要将 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/

相关文章:

java - 检查 HTTP 500 错误 HttpUrlConnection Java 中的缺陷

java - 安卓短信管理器

单选按钮的Android环形

html - 尝试对与我的网页位于同一域中的 iFrame 进行 CSS 编辑?

javascript - 根据内部内容使 iframe 高度动态化- JQUERY/Javascript

javascript - iframe 上的事件更改 src

java - 如何在java中制作IOS应用程序?

java - 为什么 doAction() 提前完成了 done() ?

java - 如何增加 JasperViewer 的宽度或高度(硬编码)?

android - IllegalStateException : The Specified child already has a parent. 您必须调用 removeView()