代码之家  ›  专栏  ›  技术社区  ›  khateeb

设置本地WebView的文本颜色

  •  -1
  • khateeb  · 技术社区  · 7 年前

    我有一个HTML字符串,它将显示在 WebView color 一个土生土长的人 网络视图 ?

    <WebView source={{ html: this.props.content }}/>
    
    2 回复  |  直到 7 年前
        1
  •  5
  •   khateeb    7 年前

    要更改HTML中文本的颜色,请将HTML包装为 div 标记并设置字体的颜色 部门 在一个 style .

    html = '<div style="color: white">' + html + '</div>';
    <WebView source={{ html: html }} />
    
        2
  •  0
  •   Rachel Gallen    7 年前

    <WebView source={{ html: "<strong>This is my Webview</strong>" }} />
    

    import React, { Component } from 'react'
    import {WebView} from 'react-native'
    class ExternalWidget extends Component {
       render()
       {
          <WebView source={{uri:'./external/widget/index.html'}} 
             scalesPageToFit/>
       }
    }
    export default ExternalWidget
    

    here

    如果您以前没有在react中使用过样式,那么它非常简单。将引用的样式导出到一个零部件中,或单独导出为text.js/颜色.js等,并使用变量引用组件类。 stylesheet 然后s.text1将获取text1类。。

        3
  •  0
  •   Piotr Labunski v_d123    5 年前
    constructor(props){
        super(props);
        this.html = this.props.data.terms_and_conditions + '<style>body{color:#464647}p,li{text-align:justify}a{color:#444}<style>'
    }
    
    render() {
        return (
            <View style={[styles.flex, { marginHorizontal:15 }]}>
               <WebView
                source={{ html: this.html }}
               />
            </View>
        );
    }
    
    推荐文章