Reputation: 1107
I want to set a background image for a webview in android. I did the following:
webView.setBackgroundColor(0);
webView.setBackgroundResource(R.drawable.backgroundImage);
I want the image to be in the middle of the webview. Any help please?
EDIT I have found the solution:
linearLayout.setGravity(Gravity.CENTER);
imageView.setBackgroundResource(R.drawable.backgroundImage);
linearLayout.addView(imageView);
frameLayout.addView(linearLayout);
frameLayout.addView(webView);
Upvotes: 4
Views: 7137
Reputation: 4433
You can also do it like this , first create a html page like
<html>
<head>
</head>
<body>
<center>
<img src="2.png"width="320" height="480" />
</center>
</body>
</html>
and then load the url page
public class Activity1
extends Activity {
WebView Webview1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.filegolfrule);
Webview1 = (WebView) findViewById(R.id.webview1);
webview.getSettings().setJavaScriptEnabled(true);
Webview1.loadUrl("file:///android_asset/a.html");
}
}
Upvotes: 0
Reputation: 1708
This below normally works for me -
WebView myWebView = (WebView) findViewById(R.id.myWebView);
myWebView.setBackgroundColor(Color.parseColor("#000000"));
Upvotes: 1