对于4.0之后的WebView空间,要想作到webView的背景透明,须要关闭WebView的硬件加速功能,能够在xml中配置此属性。以下:html
一、在xml文件中设置WebView的android:layerType属性为software。java
<WebView android:id="@+id/webview" android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layerType="software" />
二、在代码中设置WebView的setBackground属性android
int color = getResources().getColor(R.color.transparent_black); mWebView.setBackgroundColor(color); // 设置背景色
背景颜色的透明度比能够由您本身设置。web
能够测试经过测试
mWebView.loadUrl("http://www.baidu.com");
打开百度的首页测试半透明效果。spa
三、另要注意的是在编写html时注意他的背影的设置。code