我可以在 Nativescript 标签或 Textview 中使用富文本吗

Can I use rich text in Nativescript labels or Textviews

我正在构建一个应用程序,其中包含大量需要格式化的文本: 下划线 大胆的 网页链接 罢工槽 ETC, ... 我知道我可以将此格式应用于完整的文本,但没有找到对文本中的特定句子或单词执行此操作的方法。 是否有任何类型的丰富文本(例如降价)可以让我添加这种格式。

重要说明,我想在本机元素中添加此格式,而不是打开 webview 并注入 HTML 标记。

理想情况下,解决方案应该与平台无关,同时支持 IOS 和 Android 以及将来集成到 NativeScript 中的任何未来目标。

谢谢

雷蒙德

是 - 您可以使用 HTMLView 组件。 请注意,这不是使用浏览器,而是呈现原生富文本组件。

有关更多信息,请查看文档 - http://docs.nativescript.org/ApiReference/ui/html-view/HOW-TO

到目前为止,我相信这可以使用本机脚本来完成 FormattedString

它应该适用于 Android 和 iOS。下面是 Nativescript 组件使用的快速示例:

<Label class="h3 p-15 m-15 text-left">
    <FormattedString>
        <Span text="Words " color="#006600" ></Span>
        <Span text="with " color="#990000" fontAttributes="Bold"></Span>
        <Span text="different " color="#ffcc00"></Span>
        <Span text="color."></Span>
    </FormattedString>
</Label>

您可以使用支持的 CSS 相应地设置文本样式。例如,对于 udnerline 文本,您可以使用 css 属性 text-decoration: underline;