views:

1938

answers:

5

I'm trying to set the background of a webview to a drawable image resource in Android.

From the sdk it seems something like this would work but it doesn't.

WebView web = (WebView) findViewById(R.id.webView);

web.setBackgroundResource(R.drawable.backgroundmain);
web.loadData(profile, "text/html", "UTF-8");

Any idea's?

+7  A: 

As always you tend to figure these things out as soon as you ask the question. For the benefit of others, the layout that I'm using, LinearLayout, can take a background parameter that can be a colour or a resource.

So in my views .xml file I simply added a

android:background="@+drawable/backgroundmain"

and use

web.setBackgroundColor(0);

To make the webview transparent to see the background image behind.

A: 

I wish I had enough reputation to raise the vote for you. you helped me a lot...

oriharel
+4  A: 

It works perfectly if you do something like this:

webView.setBackgroundColor(0); WebView.setBackgroundResource(R.drawable.yourImage);

Jonasm
A: 

Thanks so much!!ありがとうございます。 By your favor, I got it! I can change a background for webview.

m.okayama
A: 

This is great.. This what i exactly wanted.. Thanks JamieBennett

sachin