我尝试在 WebView
中加载 YouTube 页面:
webview = (WebView) findViewById(R.id.webview);
webview.loadUrl(new String("http://youtube.com"));
但是每次我这样做时,它都会打开一个打开方式
菜单,而不是向我显示 WebView
中的页面内容,知道如何显示 youtube 页面吗? ?
最佳答案
mWebView = (WebView) findViewById(R.id.webView);
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAllowFileAccess(true);
if (Build.VERSION.SDK_INT > 7) {
settings.setPluginState(PluginState.ON);
} else {
settings.setPluginsEnabled(true);
}
String html = "";
html += "<html><body>";
html += "<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/MU9Srs04sFU?rel=0\" frameborder=\"0\" allowfullscreen></iframe>";
html += "</body></html>";
mWebView.loadData(html, "text/html", null);
愿这个逻辑(提示)对你有帮助..
关于java - WebView加载youtube页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39567867/