Alex Rivera | Logout

Android WebView background color

Asked 2012-06-06T17:35:23.517
71

I am adding to my layout a WebView to display justified text. I want to set the background of the WebView to be transparent to appear like a textView. Here's what I did:

WebView synopsis;
synopsis=(WebView)findViewById(R.id.synopsis);
synopsis.setBackgroundColor(0x00000000);

It works on the emulator, but when I run the application on my device it doesn't work: what I get is a white background.

 String textTitleStyling = "<head><style>* {margin:0;padding:0;font-size:20; text-align:justify; color:#FFFFFF;}</style></head>";
 String titleWithStyle = textTitleStyling + "<body><h1>" + movie.synopsis + "</h1></body>";
 synopsis.loadData(textTitleStyling + movie.synopsis, "text/html", "utf-8");
 synopsis = (WebView) findViewById(R.id.synopsis);
 synopsis.getSettings();
 synopsis.setBackgroundColor(0);
Edit
Report

3 Answers

119

Try setting the background like this:

WebView synopsis;
synopsis=(WebView)findViewById(R.id.synopsis);
synopsis.setBackgroundColor(Color.TRANSPARENT);
answered 2012-06-06T18:27:31.550
33

try below code hope use full for you:-

webview.setBackgroundColor(Color.parseColor("#919191"));

grey code : #919191

answered 2012-12-26T05:35:10.260
2

Did you load the css in ur webview?

Something like:

synopsis.loadData(textTileStyling, "text/html", "UTF-8");

or

synopsis.loadDataWithBaseURL("", textTileStyling, "text/html", "UTF-8", "");
answered 2012-06-10T08:42:18.097

Your Answer