Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView background color

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); 
like image 516
Vervatovskis Avatar asked Jun 06 '12 17:06

Vervatovskis


People also ask

How do I change the color of WebView?

webview. setBackgroundColor(getContext(). getResources(). getColor(android.

How do I change the background color in react native WebView?

No, you cannot change the background color of a webview, but you can use another view with your background color cover on your web view.

Is Android WebView deprecated?

This interface was deprecated in API level 12. This interface is now obsolete.


1 Answers

Try using synopsis.getSettings();

WebView synopsis; synopsis=(WebView)findViewById(R.id.synopsis); synopsis.setBackgroundColor(Color.TRANSPARENT); 
like image 166
Rookie Avatar answered Sep 28 '22 06:09

Rookie