android 字段webview几乎实现了浏览器的全部功能,最近在使用webview加载不固定格式的文章,文章中有一部分嵌入了flash,下面就是webview可以进行视频需要进行的设置,代码如下:
mWebView = (WebView) findViewById(R.id.id_webview); mWebView.loadUrl("http://abc.com/flash/kucg.swf"); // mWebView.loadDataWithBaseURL(null, // "<p>视频<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0'><param name='quality' value='high' /><param name='movie' value='http://abc.com/%E4%BC%8D%E4%BD%B0%E7%9A%84%E5%BC%9F%E5%BC%9F.flv' /><embed pluginspage='http://www.macromedia.com/go/getflashplayer' quality='high' src='http://abc.com/flash/%E4%BC%8D%E4%BD%B0%E7%9A%84%E5%BC%9F%E5%BC%9F.flv' type='application/x-shockwave-flash'></embed></object> 视频2:<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0'><param name='quality' value='high' /><param name='movie' value='http://abc.com/flash/daomeixiong.swf' /><embed pluginspage='http://www.macromedia.com/go/getflashplayer' quality='high' src='http://abc.com/flash/daomeixiong.swf' type='application/x-shockwave-flash'></embed></object></p>", // "text/html", // "utf-8", null); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setPluginsEnabled(true); mWebView.getSettings().setAllowFileAccess(true); mWebView.getSettings().setPluginState(PluginState.ON); mWebView.setBackgroundColor(0); mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { // Activity和Webview根据加载程度决定进度条的进度大小 // 当加载到100%的时候 进度条自动消失 MainActivity.this.setProgress(progress * 100); } });
同时还需设置xml文件中webview的属性,
android:layerType="software"//该属性使webview背景色透明
android:hardwareAccelerated="true"//该属性使webview支持flash播放