如何在 React Native 中更改 WebView 的背景颜色? [英] How to change the background color of WebView in React native?

查看:98
本文介绍了如何在 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.

这篇关于如何在 React Native 中更改 WebView 的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆