Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 如何在React native中更改WebView的背景色?_React Native - Fatal编程技术网

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

React native 如何在React native中更改WebView的背景色?,react-native,React Native,首先加载我的WebView,然后按下TouchableOpacity。在后台webview更改后,我是否可以在不重新启动webview的情况下执行此操作 import React, {Component} from 'react'; import {View,Text} from 'react-native' export default class TestScreen extends Component { render() { return ( <View >

首先加载我的WebView,然后按下TouchableOpacity。在后台webview更改后,我是否可以在不重新启动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>
  );
}}
import React,{Component}来自'React';
从“react native”导入{View,Text}
导出默认类TestScreen扩展组件{
render(){
返回(
);
}}

否,您不能更改web视图的背景色,但可以在web视图上使用另一个带有背景色封面的视图

import React from 'react';
import {View, StyleSheet, WebView, ActivityIndicator} from 'react-native';

export default class YourComponent extends React.PureComponent{

    state = {
        loading: true,
    };

    render() {
        return (
            <View>
                <WebView
                    source={html}
                    onLoadEnd={() => {
                        this.setState({loading: false});
                    }}
                />
                {
                    this.state.loading && (
                        <View style={{
                            ...StyleSheet.absoluteFillObject,
                            backgroundColor: '#000000',  // your color 
                            alignItems: 'center',
                            justifyContent: 'center',
                        }}>
                            <ActivityIndicator />
                        </View>
                    )
                }
            </View>
        )

    }
}
从“React”导入React;
从“react native”导入{View、样式表、WebView、ActivityIndicator};
导出默认类YourComponent扩展React.PureComponent{
状态={
加载:对,
};
render(){
返回(
{
this.setState({loading:false});
}}
/>
{
this.state.loading&&(
)
}
)
}
}

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

在WebView打开标记中添加样式道具。像这样


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