关于android:a组件在text组件内不能动态修改样式怎么破

7次阅读

共计 736 个字符,预计需要花费 2 分钟才能阅读完成。

问题形容:

a 组件放到 text 组件外部,a 组件的 style 中文字色彩是动静绑定的,批改绑定 textcolor 的值,无奈扭转 a 组件的文字色彩,比方我心愿文字色彩能从原始色彩蓝色变成红色。代码如下所示:

template 中代码:

<text>
            <a href="https://huawei.com" style="color: {{textcolor}};" value="click here"></a>
        </text>
         <input type="button" value="批改 a 的文字色彩" onclick="changeColor" />

script 中代码:

changeColor: function() {this.textcolor="red";}

问题剖析:

a 组件放到 text 组件外部时,快利用框架不反对动静扭转款式。

解决办法:

借助 text 去实现 a 的动态效果,间接在 text 组件上绑定款式(a 组件本身不绑定),能够达到成果,代码如下(见红色局部):

**<text style=”color: {{textcolor}};”>

  <a href="https://huawei.com" value="click here"></a>

</text>**

效果图(点击按钮后):

欲了解更多详情,请参阅:

快利用开发领导文档:https://developer.huawei.com/consumer/cn/doc/development/quickApp-Guides/quickapp-whitepaper


原文链接:
https://developer.huawei.com/consumer/cn/forum/topic/0204399557167870123?fid=18

作者:AppGallery Connect

正文完
 0