【问题标题】:How to highlight Text line by line in React Native如何在 React Native 中逐行突出显示文本
【发布时间】:2018-06-09 11:38:45
【问题描述】:

我想在我的 React Native 应用程序中突出显示文本。我正在使用 React Native 的 Text 组件来显示文本,我可以给它一个 backgroundColor,但我真正的高光就像你在下图中看到的那样:

【问题讨论】:

    标签: react-native text highlight


    【解决方案1】:

    您可以为此使用react-native-highlight-words 库。

    这是一个例子:

    import React, { Component } from 'react';
    import { Text, View } from 'react-native';
    import Highlighter from 'react-native-highlight-words';
    
    export default class Example extends Component {
      render() {
        return (
          <View style={{alignItems: 'center', paddingTop: 300}}>
            <Highlighter
              highlightStyle={{backgroundColor: 'greenyellow'}}
              searchWords={["Swine Flu is an infection caused by"]}
              textToHighlight="Swine Flu is an infection caused by..."
            />
            <Highlighter
              highlightStyle={{backgroundColor: 'lightblue'}}
              searchWords={["swine flu"]}
              textToHighlight="The risk of swine flu..."
            />
          </View>
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-26
      • 2018-08-25
      • 1970-01-01
      • 2020-08-12
      • 2020-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-03
      相关资源
      最近更新 更多