【问题标题】:How do I set link color in Nativescript HtmlView tag?如何在 Nativescript HtmlView 标签中设置链接颜色?
【发布时间】:2019-11-12 05:59:57
【问题描述】:

我需要在 iOS 上更改 HtmlView 中的链接颜色。在 Android 上,我可以通过编辑 /app/App_Resources/Android/src/main/res/values/colors.xml 来设置默认颜色。我找不到如何在 iOS 上做到这一点的方法。任何帮助将不胜感激。

我尝试使用内联样式 {N} 属性,但似乎没有任何影响链接的颜色。它适用于段落标签或跨度,但它不影响链接。

简化/解释代码


    <HtmlView html="
        <span>just some text </span>
        <br>
        <p style='text-align: center;'>
            <span style='color: red;'>this will get colored </span>
            <br>
            <a href='https://google.com'>link - this will not get colored</a>
        </p>
    "></HtmlView>

图像在设备上的外观:

我无法在此处将其添加为图像...它需要 10 多个我没有的声望。

提前感谢您的任何建议。

【问题讨论】:

  • 在图像中颜色已经以红色突出显示,所以您是说要为 HTML 中的其余文本设置默认颜色?
  • @Manoj 我需要对链接进行着色。正如我之前提到的,除了链接(A 标签)之外的所有东西都有效。 我可能应该提一下,我在 iOS 上需要的是让蓝色变成绿色,就像在 android 版本上一样。

标签: nativescript nativescript-vue


【解决方案1】:

您可以在原生对象上调整 tintColor (iOS) / textColorLink (Android)。

HTML

     <HtmlView @loaded="onLoaded" html="
        <span>just some text </span>
        <br>
        <p style='text-align: center;'>
            <span style='color: red;'>this will get colored </span>
            <br>
            <a href='https://google.com'>link - this will not get colored</a>
        </p>
    "></HtmlView>

方法

import * as colorModule from "tns-core-modules/color";

onLoaded: function(args) {
   const color = new colorModule.Color("green");
   if (args.object.ios) {
      args.object.ios.tintColor = color.ios;
   } else {
      args.object.android.setLinkTextColor(color.android);
   }
}

【讨论】:

  • 我会尝试并告诉你。非常感谢您的回答。
  • 谢谢!!有用!!非常感谢您的帮助。
猜你喜欢
  • 2015-04-22
  • 2015-09-04
  • 1970-01-01
  • 1970-01-01
  • 2022-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多