public class MyPdfViewActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView mWebView=new WebView(MyPdfViewActivity.this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl(youtube_link);
setContentView(mWebView);
}
}
更新::
如果上述方法不起作用,请尝试以下方法::
public class main extends Activity {
/** Called when the activity is first created. */
@ Override
public void onCreate (Bundle savedInstanceState) {
super. onCreate (savedInstanceState);
setContentView (R.layout.main);
WebView web = (WebView) findViewById (R.id.webView);
web. getSettings().setJavaScriptEnabled (true);
web. getSettings().setJavaScriptCanOpenWindowsAutomatically (false);
web. getSettings().setPluginsEnabled (true);
web. getSettings().setSupportMultipleWindows (false);
web. getSettings().setSupportZoom (false);
web. setVerticalScrollBarEnabled (false);
web. setHorizontalScrollBarEnabled (false);
web. loadUrl ("THE URL TO YOUR WEBVIEW SITE SHOULD GO HERE");
web. setWebViewClient (new WebViewClient () {
@ Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("vnd.youtube")){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
else
{
return false;
}
}
});
}
}