David Caunt

Mobile Software Engineer

Subscribe to my RSS feed

Posts Tagged ‘android’

WebView gradient backgrounds

April 5th, 2011

One of those easy questions shot up on Stack Overflow where a few people quickly jump in with an answer. How do you set a gradient background on a view?

Three answers later and the question poster refines his question: “What about a WebView?” While we all assumed the answer to be the same, WebViews ignore any background drawable used while a background colour is set. The default background colour for a WebView is white, so you need to make it transparent.

Simply specify 0 as your colour and add a drawable in code or via layout XML.

WebView webview = (WebView)findViewById(R.id.wv);
webview.setBackgroundColor(0);
webview.setBackgroundResource(R.drawable.gradient);

You can view the original discussion on Stack Overflow.

Top