口味

「Flavor」會指定一組設定值,並分組為預設值。 一般來說,使用者可以在隨附應用程式中選擇這些口味。

Flavor 可包含現有設定的值,包括 下列類型:

  • BooleanConfiguration
  • ColorConfiguration
  • ListConfiguration
  • ComplicationSlot

自第 2 版起

語法

<Flavor id="string" displayName="string" icon="string"
    screenReaderText="string">
    <!-- Flavor-specific child elements. -->
    <Configuration ... />
    <ComplicationSlot .../>
<Flavor/>>

您可以在 UserConfigurations 元素內加入 Flavor 元素。 如以下範例所示:

<UserConfigurations>
  <!-- Configuration definitions go here -->
  <ColorConfiguration id="themeColor" ... />
  <!-- ... -->

  <!-- The defaultValue is required. Set this attribute to the ID
       of the flavor that the system should show by default. -->
  <Flavors defaultValue="1">
    <Flavor id="1" displayName="1st flavor" icon="flavor_1_preview">
        <Configuration id="themeColor" optionId="0"/>
        <ComplicationSlot slotId="0">
            <DefaultProviderPolicy
                defaultSystemProvider="DAY_OF_WEEK"
                defaultSystemProviderType="SHORT_TEXT"/>
        </ComplicationSlot>
    </Flavor>

    <Flavor id="2" displayName="2nd flavor" icon="flavor_2_preview">
        <Configuration id="themeColor" optionId="1"/>
        <ComplicationSlot slotId="0">
            <DefaultProviderPolicy
                defaultSystemProvider="WATCH_BATTERY"
                defaultSystemProviderType="SHORT_TEXT"/>
        </ComplicationSlot>
    </Flavor>
  </Flavors>
</UserConfigurations>

如要使用「Flavors」,必須將下列項目新增至 res/xml/watch_face_info.xml

<?xml version="1.0" encoding="utf-8"?>
<WatchFaceInfo>
    ...
    <MultipleInstancesAllowed value="true" />
    <FlavorsSupported value="true" />
</WatchFaceInfo>

屬性

Flavor 元素的屬性如下:

必要屬性

必要屬性包括:

id
Flavor 的專屬 ID。
displayName
與隨播廣告中顯示的文字相對應的資源 ID。

選用屬性

選用屬性包括:

icon
與顯示的可繪製資源相對應的資源 ID 隨播廣告。大小上限為 360x360 像素。
screenReaderText
與使用者所使用文字相對應的資源 ID 已啟用 TalkBack

內部元素

Flavor 元素必須包含至少一個 Configuration 元素,且可以 選擇性地加入 ComplicationSlot 元素。

  • Configuration 元素參照先前定義的設定 元素,如 BooleanConfiguration,則使用 id 屬性。 Configuration 元素會設定這個設定選項的選定值 使用 optionId 屬性即可。

  • ComplicationSlot 元素可用來指定 指定 FlavorDefaultProviderPolicy