简体   繁体   English

在flex列表中的标签上添加颜色

[英]Add color to label on list in flex

I am confused on how to get this.. so i have a user list when someone joins it adds them to a List (their username) i have a way to find out if they are admin or not i just need to know how i can change the color of each user in that list... this is an example.... 我对如何获取感到困惑..所以当有人加入时我有一个用户列表,将他们添加到列表(他们的用户名)中,我有办法找出他们是否是管理员,我只需要知道我能更改该列表中每个用户的颜色。这是一个示例。

If list supported html this would work fine 如果列表支持HTML,则可以正常工作

onlineUsers.addItem({label:"<font color='$ffffff'>users[i].userName+"_GUEST</font>",id:users[i].userID,guest:"True"});
userList.dataProvider = onlineUsers

But list do not support html, anyone know a work around with this? 但是列表不支持html,有人知道可以解决此问题吗?

Generically, your answer is to use an itemRenderer. 通常,您的答案是使用itemRenderer。

All a list class does is display other components (renderers) and send those components data from the dataProvider to display. 列表类所做的只是显示其他组件(渲染器),并从dataProvider发送这些组件数据以进行显示。 Really, you mean the default itemRenderer doesn't support HTML. 确实,您的意思是默认的itemRenderer不支持HTML。 Technically you could make an itemRenderer that would support HTML to give you the color change you need; 从技术上讲,您可以制作一个支持HTML的itemRenderer,以提供所需的颜色更改。 but I'd take a different. 但我会有所不同。

Add a property to the user object that specifeis whether they are an admin user or not. 向用户对象添加一个属性,该属性具体说明它们是否是管理员用户。 Then iF the user is an admin user; 则该用户为管理员用户; then; 然后; change the color. 改变颜色。 Conceptually like this: 在概念上是这样的:

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark"
    autoDrawBackground="false" dataChange="onDataChange()">

    <fx:Script>
        <![CDATA[
            public function onDataChange():void{
               labelDisplay.text = data.userName + "_Guest";
               if(data.isAdmin){
                 labelDisplay.setStyle('color',0xff0000);
               } else {
                 labelDisplay.setStyle('color',0x00FF00);
               }
            }
        ]]>
    </fx:Script>

    <s:Label id="labelDisplay" 
        /> 
</s:ItemRenderer>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM