2014-11-21 63 views
0

在我的程序中,我製作了一個讀取xml博客的功能,並將標題放在TListBox中。但我需要更改TListBoxItem中的一些屬性,如字體,高度和顏色,但不會更改。如何在運行時更改android應用程序中的TlistBoxItem屬性?

如何在運行時設置它?

repeat 
    Title := ANode.ChildNodes['title'].Text; 
    Link := ANode.ChildNodes['link'].Text; 
    Desc := ANode.ChildNodes['description'].Text; 
    DataPub := ANode.ChildNodes['pubDate'].Text; 
    SetLength(Vet_News, Pos + 1); 
    Vet_Nesw[Pos] := '<h2>'+Title+'</h2>'+Desc; 
    Itemx := TListBoxItem.Create(self); 
    Itemx.Text := Title; 
    Itemx.ItemData.Detail := DataPub; 
    Itemx.ItemData.accessory := TListBoxItemData.TAccessory.aMore; 
    Itemx.TextSettings.WordWrap := true; 
    Itemx.TextSettings.FontColor := TAlphaColorRec.Darkorange; 
    Itemx.Height := 65; 
    Itemx.FontColor := TAlphaColorRec.Darkorange; // i tried two ways to change the color 
    lbNews.AddObject(Itemx); // lbnews is a Tlistbox 
    Inc(Pos); 
    ANode := ANode.NextSibling; 
until ANode = nil; 
+0

您可能需要更改TListBox或列表框項目的樣式。 – 2014-11-22 12:46:27

+0

另一個想法?只有在運行時我無法更改設置。 – Murilo 2014-12-02 18:11:37

+0

Via StyleLookup(該項目)?更改項目使用的樣式,或更改查找以引用新樣式。否則,你能擴展你的問題嗎? – 2014-12-02 21:22:43

回答

0

在運行[用Delphi-XE7測試],Listboxitems已經存儲在計算風格:aListboxItem.StyledSettings。 要在運行時更改設置,首先必須將其從樣式化設置列表中刪除。

例如,如果你想改變FontColor,首先刪除樣式FONTCOLOR:

aListboxItem.StyledSettings := aListboxItem.StyledSettings - [TStyledSetting.FontColor]; 

然後申請另一個(比方說綠色):

aListboxItem.FontColor := TAlphaColors.Green; 

TStyledSetting常量和相應的TTextSettings房源列表here in Delphi's doc

在運行時更改樣式的示例可以找到herethere

Nota Bene:theListBox.Items[i]可以訪問項目內容,而不是項目本身。 搶ListBoxItem的作爲對照,然後在其屬性行動,你可以使用:

aListboxItem := theListBox.ListItems[i]; 

aListboxItem := theListBox.ItemByIndex(i); 

兩個賦予完全相同的結果,我不能說,如果一個更好。

相關問題