复杂功能

<ph type="x-smartling-placeholder"></ph>

Complication 元素用于定义特定复杂功能类型在表盘上的显示方式。

针对每种类型的复杂功能,您可以在表达式中使用以下代码。这样,您就可以访问提供给复杂功能的数据:

  • 所有类型,以及 EMPTY
    • [COMPLICATION.TYPE]
    • [COMPLICATION.TAP_ACTION]
  • LONG_TEXT
    • [COMPLICATION.MONOCHROMATIC_IMAGE]
    • [COMPLICATION.MONOCHROMATIC_IMAGE_AMBIENT]
    • [COMPLICATION.TEXT]
    • [COMPLICATION.TITLE]
  • MONOCHROMATIC_IMAGE
    • [COMPLICATION.MONOCHROMATIC_IMAGE]
    • [COMPLICATION.MONOCHROMATIC_IMAGE_AMBIENT]
  • PHOTO_IMAGE
    • [COMPLICATION.PHOTO_IMAGE]
  • RANGED_VALUE
    • [COMPLICATION.MONOCHROMATIC_IMAGE]
    • [COMPLICATION.MONOCHROMATIC_IMAGE_AMBIENT]
    • [COMPLICATION.TEXT]
    • [COMPLICATION.TITLE]
    • [COMPLICATION.RANGED_VALUE_MIN]
    • [COMPLICATION.RANGED_VALUE_MAX]
    • [COMPLICATION.RANGED_VALUE_VALUE]
    • [COMPLICATION.RANGED_VALUE_COLORS] -(以空格分隔的十六进制列表) 颜色,例如 #FF0000 #00FF00
    • [COMPLICATION.RANGED_VALUE_COLORS_INTERPOLATE]:一个布尔值,用于指定 是否插入颜色)
  • SHORT_TEXT
    • [COMPLICATION.MONOCHROMATIC_IMAGE]
    • [COMPLICATION.MONOCHROMATIC_IMAGE_AMBIENT]
    • [COMPLICATION.TEXT]
    • [COMPLICATION.TITLE]
  • SMALL_IMAGE
    • [COMPLICATION.SMALL_IMAGE]
    • [COMPLICATION.SMALL_IMAGE_AMBIENT]
    • [COMPLICATION.IMAGE_STYLE] -(对应于 SmallImageType 序数值)
  • GOAL_PROGRESS
    • [COMPLICATION.GOAL_PROGRESS_VALUE]
    • [COMPLICATION.GOAL_PROGRESS_TARGET_VALUE]
    • [COMPLICATION.TEXT]
    • [COMPLICATION.TITLE]
    • [COMPLICATION.GOAL_PROGRESS_COLORS] -(以空格分隔的十六进制列表) 颜色,例如 #FF0000 #00FF00
    • [COMPLICATION.GOAL_PROGRESS_COLORS_INTERPOLATE]:一个布尔值,用于指定 是否插入颜色)
  • WEIGHTED_ELEMENTS
    • [COMPLICATION.WEIGHTED_ELEMENTS_COLORS] -(以空格分隔的十六进制列表) 颜色,例如 #FF0000 #00FF00
    • [COMPLICATION.WEIGHTED_ELEMENTS_WEIGHTS] -(以空格分隔的 元素权重)
    • [COMPLICATION.WEIGHTED_ELEMENTS_BACKGROUND_COLOR]
    • [COMPLICATION.TEXT]
    • [COMPLICATION.TITLE]

如需查看完整演示,请参阅示例

此元素在 Wear OS 4 中推出。

语法

<Complication type="string">
      <!-- Only the most common inner element is shown here. -->
      <Group>
      </Group>
</Complication>

示例

以下示例展示了一项包含图片、标题和文本组件的复杂功能:

<Complication type="SHORT_TEXT">
    <PartImage x="35" y="16" width="22" height="22" pivotX="0.5" pivotY="0.5"
               name="SomeIcon" alpha="255">
        <Image resource="[COMPLICATION.MONOCHROMATIC_IMAGE]"/>
    </PartImage>
    <PartText x="18" y="39" width="56" height="22" pivotX="0.5" pivotY="0.5"
              name="SomeText" alpha="255">
        <Text align="CENTER" ellipsis="TRUE">
            <Font family="SYNC_TO_DEVICE" size="20" weight="NORMAL"
                  slant="NORMAL" color="#ffffffff">
                <Template>
                    %s
                    <Parameter expression="[COMPLICATION.TEXT]"/>
                </Template>
            </Font>
        </Text>
    </PartText>
    <PartText x="19" y="62" width="54" height="14" pivotX="0.5" pivotY="0.5"
              name="SomeTitle" alpha="255">
        <Text align="CENTER" ellipsis="TRUE">
            <Font family="SYNC_TO_DEVICE" size="12" weight="NORMAL"
                  slant="NORMAL" color="#ffadadad">
                <Template>
                    %s
                    <Parameter expression="[COMPLICATION.TITLE]"/>
                </Template>
            </Font>
        </Text>
    </PartText>
</Complication>

属性

ComplicationSlot 元素必须包含 type 属性。如果用户选择匹配的复杂功能类型,系统将呈现此元素。支持的值包括 SHORT_TEXTLONG_TEXTMONOCHROMATIC_IMAGESMALL_IMAGEPHOTO_IMAGERANGED_VALUEEMPTY

内部元素

Complication 元素可以包含任意数量的以下内部元素: