How to make a transparent WebView in Android
Today one of my subscribers (@prasad) ask me: “how to make a transparent webview behind a gridview.”
I don’t have complete example for it, but this info might help you.
Do do transparent WebView I create this layout:
<?xml version="1.0" encoding="UTF-8"?>
<!--?xml version="1.0" encoding="utf-8"?-->
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ff0000">
<webview android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</linearlayout>
Notice, that backgroung behind WebView is RED
And here I have sourcecode of Activity:
package com.hrupin.transparent_webview;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class Transparent_webviewActivity extends Activity {
private WebView webview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webView1);
// Here is I make transparent background for WebView
webview.setBackgroundColor(0x00000000);
String summary = "<h1>The content of the document......</h1>";
webview.loadData(summary, "text/html", null);
}
}
That’s all.
It works for me on Android 2.3.3 (Gingerbread). Device is HTC Desire.
1 Comment
prasad · 9 August, 2012 at 11:47
thanks bro the thing is that when i click on the button gridview in coming ..above the webview but when i again click on the same button gridview dissappear but that space is occupied…i want gridview to dissappear but the webview should occupy whole page then plz help bro iam stuck here