react-native:多色文本视图 [英] react-native: multi color text view

查看:36
本文介绍了react-native:多色文本视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想渲染一行文本,其中一些单词以不同颜色突出显示.

I want to render a single line of text with some words highlighted in a different color.

理想情况下,我会使用带有 react 的 span 标签来实现.

I would ideally do it with a span tag with react.

想知道如何使用 react-native 做同样的事情?

Wondering how would i do the same with react-native?

推荐答案

您可以通过使用嵌套的 Text 组件来实现这一点

You can achieve this by using nested Text components

<Text style={{color: 'blue'}}>
    I am blue
    <Text style={{color: 'red'}}>
        i am red
    </Text>
    and i am blue again
</Text>

这是解释它的文档的链接更好

Here's a link to the documentation explaining it better

这篇关于react-native:多色文本视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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