Android WebView样式background-color:transparent

我正在努力创建具有透明背景的WebView。


webView.setBackgroundColor(0x00FFFFFF);

webView.setBackgroundDrawable(myDrawable);

然后我加载一个html页面


<body style="background-color:transparent;" ...

WebView的背景颜色是透明的,但是一旦加载页面,它就会被html页面中的黑色背景覆盖。这仅发生在android 2.2上,它适用于android 2.1。


那么,在html页面代码中是否要添加一些内容以使其真正透明?


慕少森
浏览 1214回答 3
3回答

慕仙森

这对我有用mWebView.setBackgroundColor(Color.TRANSPARENT);

UYOU

我在2.2和2.3中都有相同的问题。我通过在html中而不是在android中提供alpa值解决了问题。我尝试了很多事情,发现setBackgroundColor();颜色不能与alpha值一起使用。webView.setBackgroundColor(Color.argb(128, 0, 0, 0));不管用。所以这是我的解决方案,为我工作。&nbsp; &nbsp; &nbsp; String webData = StringHelper.addSlashes("<!DOCTYPE html><head> <meta http-equiv=\"Content-Type\" " +&nbsp; &nbsp; &nbsp; "content=\"text/html; charset=utf-8\"> </head><body><div style=\"background-color: rgba(10,10,10,0.5); " +&nbsp; &nbsp; &nbsp; "padding: 20px; height: 260px; border-radius: 8px;\"> $$$ Content Goes Here ! $$$ </div> </body></html>");在Java中&nbsp; &nbsp; webView = (WebView) findViewById(R.id.webview);&nbsp; &nbsp; webView.setBackgroundColor(0);&nbsp; &nbsp; webView.loadData(webData, "text/html", "UTF-8");
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android