Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Blackberry 基于标签值的标签颜色_Blackberry_Blackberry 10 - Fatal编程技术网

Blackberry 基于标签值的标签颜色

Blackberry 基于标签值的标签颜色,blackberry,blackberry-10,Blackberry,Blackberry 10,我有一个容器,上面有这样的标签。。。 但是如果标签值为负值,我需要添加红色,否则为绿色。如何在Qml中的BB 10级联中执行此操作 Container { leftPadding: 15.0 rightPadding: 15.0 layout: StackLayout { orientation: LayoutOrientation.LeftToRight } topPadding: 20.0 Label { id

我有一个容器,上面有这样的标签。。。 但是如果标签值为负值,我需要添加红色,否则为绿色。如何在Qml中的BB 10级联中执行此操作

Container {
    leftPadding: 15.0
    rightPadding: 15.0
    layout: StackLayout {
        orientation: LayoutOrientation.LeftToRight
    }
    topPadding: 20.0

    Label {
        id: symbol
        text: ListItemData.Symbol_En

        // Text Style and size etc
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 4
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

    }
    Label {
        id: change
        text: ListItemData.PerChange
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 2
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

    }
    Label {
        id: ltp
        text: ListItemData.LTP
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 1
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

    }
    Label {
        id: highValue
        text: ListItemData.High
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 1
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

    }
    Label {
        id: lowValue
        text: ListItemData.Low
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 1
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

    }

像这样的东西怎么样(只是有问题的标签):

标签{
id:高值
文本:ListItemData.High
textStyle.color:ListItemData.High.indexOf(“-”)小于0?颜色。绿色:颜色。红色
textStyle.base:SystemDefaults.TextStyles.subtitlettext
textStyle.fontSizeValue:30.0
layoutProperties:StackLayoutProperties{
名额:1
}
垂直对齐:垂直对齐。中心
水平对齐:水平对齐。居中
}

您想给哪个标签上色?哪个值?id为highValue的标签。如果是负片,我需要红色,绿色,但这里是ListItemData。是否可以像ListItemData.High.contains('-')那样进行比较?你用parseInt怎么样。我在中添加了它,而不是.contains,您可以使用.indexOf(“-”)0。如果里面有“-”,则会得到0,否则会得到-1ListItemData.High.indexOf(“-”),请尝试打印数据,看看会得到什么。我测试了这个,它是有效的<代码>.indexOf(“-”)是否小于0?颜色.绿色:颜色.红色
Label {
        id: highValue
        text: ListItemData.High
        textStyle.color: ListItemData.High.indexOf("-") < 0 ? Color.Green : Color.Red 
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 1
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center
    }