How do I set the background color of a WebView
to a hexadecimal value? I am open to either via main.xml
or programmatically.
Background-color values can be expressed in hexadecimal values such as #FFFFFF, #000000, and #FF0000. Background-color values can be expressed using rgb such as rgb(255,255,255), rgb(0,0,0), and rgb(255,0,0). Background-color values can be expressed as named colors such as white, black, and red.
A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and BB (blue) hexadecimal integers specify the components of the color.
But you can also use Format Cells and the Fill Tab, Click More Fill, then Custom and you can type in the Hex at the bottom and it will give you the Colours as well as the RGB numbers. You could also then apply Conditional Formatting so when a HEX number is used it colours the cell automatically for you.
Assuming you have defined your WebView
in an XML resource, you can do the following:
WebView myWebView = (WebView) findViewById(R.id.myWebView);
myWebView.setBackgroundColor(Color.parseColor("#000000"));
In xml:
<WebView
android:background = "#7CFC00"
/>
for green etc..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With