如何在 React Native 中更改 WebView 的背景颜色?

问题描述:

我的 WebView 首先加载,然后按下 TouchableOpacity.是否可以在后台 webview 更改后不重新启动 webview 执行此操作?

My WebView first loads and TouchableOpacity is pressed after it. Can I do this after the background webview has changed without restarting the webview?

import React, {Component} from 'react';
import {View,Text} from 'react-native'

export default class TestScreen extends Component {
render() {
return  (
    <View >
        <TouchableOpacity onPress={/*what is the function that changes the background color of the webview after loading it (but without reloading the Webview)*/}>
         <WebView>
       </TouchableOpacity>

     </View>
  );
}}

是的.你可以.您实际上可以通过这样做来更改 webview 的背景颜色.

Yes. You can. You can actually change the background color of the webview by doing this.

在 WebView 开始标签中添加样式道具.像这样

Add a style prop in the WebView opening tag. like this

<WebView 
  style={{
    backgroundColor: 'green'
  }}
/> 

这会将 webview 的背景设置为绿色.

this sets the background of the webview to green.