android 的webView的透明設置

對於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

相關文章
相關標籤/搜索