react-native的WebView背景颜色是无法改变的,不过我们可以用另一个View盖住WebView,达到改变颜色的效果。
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>
)
}
}