简体   繁体   中英

How to set the background color of a WebView to a hex value?

How do I set the background color of a WebView to a hexadecimal value? I am open to either via main.xml or programmatically.

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..

从onCreate尝试这个:

myWebView.setBackgroundColor(0x7CFC00);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM