Dynamically change element content

While Transform lets you change the appearance of elements or groups of elements, there might be occasions where you want to switch between a list of behaviors based on some condition. This is analogous to a switch statement or if...else statement in other languages.

For example, you might want to show a different background for early morning, morning, lunch, afternoon, evening, and night.

Condition statements in Watch Face Format let you include different parts of your watch face scene depending on the evaluation of expressions, for example:

<Condition>
<Expressions>
<Expressionname="is_early_morning">
<![CDATA[[HOUR_0_23]>=6 && [HOUR_0_23] < 8]]
</Expression>
<Expressionname="is_morning">
<![CDATA[[HOUR_0_23] < 12]]
</Expression>
<!--Furtherexpressions-->
</Expressions>
<Compareexpression="is_early_morning">
<!--Earlymorningcontenthere-->
</Compare>
<Compareexpression="is_morning">
<!--Morningcontenthere-->
</Compare>
<!--FurtherCompareelements-->
<!--The"else"case-->
<Default>
<!--content-->
</Default>
</Condition>

A few things to note about conditions:

  1. The first Compare element where the expression is true is used, and others are ignored.
  2. Owing to the XML format, it can often be easiest to wrap the expression definition in a CDATA element as shown here, as this avoids the need for XML escaping using entity elements such as &gt; and &amp;.
  3. Condition structures can be nested.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026年07月21日 UTC.