titanium-sdk
titanium-sdk copied to clipboard
feat(android): more attributedString link features
Currently the attributedString link is not very flexible in terms of color and removing the underline.
This PR adds two new features:
-
linkColorfor the label: allows to set the color of the autoLink or attributedString link. Note: currently we can use another attributeTi.UI.ATTRIBUTE_FOREGROUND_COLORto color the link. This works for both Android and iOS. But there is not way to color a link withautoLink(Android only). So we won't need iOS parity for this property. -
a new attribute
underlinein the attributedString that can be used in combination withtype: Titanium.UI.ATTRIBUTE_LINKto remove the underline from the link
var win = Titanium.UI.createWindow({
layout: "vertical"
});
win.open();
var text = 'just one link';
var attr = Titanium.UI.createAttributedString({
text: text,
attributes: [{
type: Titanium.UI.ATTRIBUTE_LINK,
value: "https://titaniumsdk.com",
range: [text.indexOf('one'), ('one').length],
underline: false
}]
});
// custom link color - attributedString
var label = Titanium.UI.createLabel({
height: Titanium.UI.SIZE,
attributedString: attr,
linkColor: "red"
});
// custom link color - autoLink
var label2 = Titanium.UI.createLabel({
height: Titanium.UI.SIZE,
text: " this is a https://titaniumsdk.com test",
linkColor: "blue",
autoLink: true
});
// current default link color
var label3 = Titanium.UI.createLabel({
height: Titanium.UI.SIZE,
text: " this is a https://titaniumsdk.com test",
autoLink: true
});
win.add([label, label2, label3]);