2016-03-18 45 views
1

我正在開發一個列表,我想通過以紅色顯示字體顏色來突出顯示某些行。這可能嗎?如何設置libgdx列表中特定行的顏色?

編輯: 好吧,這裏簡化我的代碼版本:

Skin defListSkin = new Skin(Gdx.files.internal("data/uiskin.json")); 

List listHistory = new List<String>(defSkin); 

// Here I set the general font color for the list 
List.ListStyle listStyle = listHistory.getStyle(); 
listStyle.font = fontList; 
listStyle.fontColorUnselected = Color.LIGHT_GRAY; 
listHistory.setStyle(listStyle); 

String[] items = new String[20]; 

// Example of item[] 
// item[0]: "John 12" 
// item[1]: "Amy -3" <-- I want certain lines to appear in red (e.g. those with negative numbers) 

// Populate the list 
listHistory.setItems(items); 

// Drawing the list (actual draw happens in render() of course) 
Table myTable = new Table(); 
myTable.add(listHistory); 
stage.addActor(myTable); 
+0

太過模糊:)給我們帶來什麼你試過,也許你正試圖實現的截圖。 – Enigo

+0

你現在怎麼畫線?你有某種'列表'。你可以做'spriteBatch.setColor(..)'。 – Madmenyo

回答

2

使用Libgdx支持的顏色標記語言。

的標記語法是非常簡單的,但仍然多才多藝:

[名] name設置顏色。有幾種預定義的顏色,請參閱Colors.reset()方法以獲得詳盡的列表。用戶可以通過Colors類的方法來定義自己的顏色。 [#xxxxxxxx]設置由十六進制值xxxxxxxx指定的顏色,格式爲RRGGBBAA,其中AA是可選的,默認爲0xFF。 []將顏色設置爲以前的顏色(可選結束標籤的種類) [[將左括號移出。

默認情況下禁用標記。使用public member font.getData()。markupEnabled打開/關閉它。

參考:https://github.com/libgdx/libgdx/wiki/Color-Markup-Language

如果你想要一個像標記更復雜的HTML,您可以使用這些模板:https://github.com/czyzby/gdx-lml,現場測試:http://czyzby.github.io/gdx-lml-tests/

+0

優秀 - 它的作品!我不知道顏色標記語言。謝謝你。 – go3d

+0

很高興幫助:) – Hllink

0

我知道你的意思,我不認爲這是可能的。列表項都鏈接到相同的listStyle,並且更改列表項顏色的唯一方法是爲listHistory創建新樣式並更改此樣式的字體顏色,但是如果您這樣做,它會更改每個項目在列表中以新的字體顏色顯示。我的建議是創建兩個單獨的列表和兩個單獨的ListStyles,並且您想要的紅色線條位於一個列表中,並且具有一種樣式,並且您不希望變爲紅色的線條位於另一個列表中並且具有不同的樣式。希望這有助於

相關問題