1

I have a webview in one of lay out and I want make the background color of the webview transparent. I tried the some different ways and

webView.setBackgroundColor(Color.argb(128, 0, 0, 0));

this one worked for me. But the problem is I cannot make the whole webview transparent, only the right side of the webview has a tiny strip transparent background and the rest of the webview has black background. Any Idea for making whole webview transparent ? Here I have uploaded screenshot and you can check out my xml and java code. and if you also know how to make the view has radius borders it could also be nice. Thanks

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.aboutus);

    String webData = StringHelper.addSlashes("<font color=\"#6495ed\">TEST</font>");

    webView = (WebView) findViewById(R.id.webview);
    webView.loadData(webData, "text/html", "UTF-8");
    webView.setBackgroundColor(Color.argb(128, 0, 0, 0));
}

<?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="@drawable/bg2"
android:weightSum="100" >

<ImageView 
    android:id="@+id/about_us_header_image"
    android:layout_height="0dip"
    android:layout_width="match_parent"
    android:background="@drawable/header"
    android:layout_weight="20"
    android:visibility="invisible"
    />

<WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="80"
    android:layout_margin="20dp"
    />
</LinearLayout>

enter image description here

osayilgan
  • 5,873
  • 7
  • 47
  • 68
  • 1
    Try setting a transparent background color in your html page. – Steelight May 31 '12 at 13:54
  • I'm not sure that will work for my case. Because I will be having the html dynamically from a web page. – osayilgan May 31 '12 at 14:01
  • It will at least let you know if the problem is there. – Steelight May 31 '12 at 14:08
  • Yeah I tried it with different background color and it works. But the thing is transparent background is not working. it still shows the color not with opacity – osayilgan May 31 '12 at 15:03
  • @Steelight it worked by giving background color and alpha value in HTML. I was trying to do it in HTML and Java at the same time and it was not working untill I simply set the background color `setBackgroundColor(0);` and I gave the apha in HTML by this in a constant div. `style=\"background-color: rgba(10,10,10,0.5); "` – osayilgan Jun 01 '12 at 07:18
  • 1
    and see my solution here. [link](http://stackoverflow.com/questions/5003156/android-webview-style-background-colortransparent-ignored-on-android-2-2/) – osayilgan Jun 01 '12 at 07:22

1 Answers1

1

After searching on the stackoverflow I've seen that its not only having this issue, and I found a work around for the devies 2.2xx and 2.3xx here is the link below..

Here is the link to my Solution.

Community
  • 1
  • 1
osayilgan
  • 5,873
  • 7
  • 47
  • 68