如何更改自定义 table 行 Titanium 中的标签属性

how to change label properties in custom table row Titanium

我有一个 table 视图,其中每一行都包含一个标签,所以我想做的是更改标签背景颜色和用户点击时的颜色
但我得到的只是改变颜色,背景颜色只是在用户点击时改变,然后返回默认颜色

这是我的听众:

 s_f_table1.addEventListener("click", function(e) {
       e.source.setBackgroundColor("red");
       e.source.color = "black";
       console.log(e.source.id);

});

如果您使用的是自定义布局,试试这个:

tableView.addEventListener("click", function(e) {
   var label = e.row.children[0]; // Label doesn't has to be the first child, depend on your layout.

   label.color = "black";
   label.backgroundColor = "red";
});

但是,如果您有默认行样式,则可以将属性设置为 selectedBackgroundColorselectedColorselectionStyle。请参阅文档 http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.TableViewRow

或者您可以执行以下操作:

tableView.addEventListener("click", function(e) {    
   e.row.color = "black";
   e.row.backgroundColor = "red"; // Whole row
});

编辑: 如果要更改背景颜色,请不要忘记禁用行的 selectionStyle 使用:selectionStyle: Ti.UI.iPhone.TableViewCellSelectionStyle.NONE