无法更改属性字符串的文本颜色

时间:2018-04-26 15:25:19

标签: string appcelerator

var attr = Titanium.UI.createAttributedString({             text:value,

        attributes: [{
                type: Ti.UI.ATTRIBUTE_LINK,
                range: [0, value.length],
                value: Titanium.UI.ATTRIBUTE_UNDERLINE_STYLE_SINGLE,
            },
            {
                type: Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
                value: '#CD1625',
                range: [0, value.length],
            },
            {
                type: Ti.UI.ATTRIBUTE_UNDERLINE_COLOR,
                value: '#CD1625',
                range: [0, value.length],
            }
        ]


    });

    credDetailsValue = Ti.UI.createLabel({
        attributedString: attr,
        width: "70%"
    });

无法更改TEXT下划线的颜色正在运行

1 个答案:

答案 0 :(得分:0)

ATTRIBUTE_UNDERLINE_COLOR仅适用于iOS(请参阅文档),ATTRIBUTE_FOREGROUND_COLOR可以正常使用:

var win = Ti.UI.createWindow({
    backgroundColor: 'white'
});
var value = "this is a text this is a text this is a text";

var attr = Titanium.UI.createAttributedString({
    text: value,

    attributes: [{
        type: Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
        value: '#CD1625',
        range: [0, 5],
    }, {
        type: Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
        value: '#00ff00',
        range: [5, 10],
    }, {
        type: Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
        value: '#0000ff',
        range: [10, 15],
    }]
});

var lbl = Ti.UI.createLabel({
    attributedString: attr,
    width: "70%"
});
win.add(lbl);
win.open();