本指南除了介紹以錶面格式設定錶面所需的工具,以及這些工具的使用步驟外,也針對專案架構提供了一些建議,包括逐步講解如何將工具應用於建立這個架構。
必要條件
為了讓開發環境做好使用錶面格式的準備,請完成下列設定步驟:
- 安裝適用於 Android 13 (API 級別 33) 以上版本的 SDK。這個 SDK 內含其他必要工具,包括
aapt2
和android.jar
。 - 安裝
bundletool
指令列程式。 - 找出含有表面設計的應用程式,簽署該應用程式的偵錯版本。您可以在 Android Studio 中產生已簽署的 Android App Bundle,也可以手動簽署偵錯版本。
專案架構
當您使用錶面格式建立自訂錶面時,必須將包含自訂錶面檔案的 Android App Bundle 與包含 Wear OS 應用程式邏輯的 Android App Bundle 完全區隔開來。部分應用程式商店 (包括 Google Play) 會禁止上傳同時包含 Wear OS 邏輯和自訂錶面的 Android App Bundle。
建立錶面套件
如要建立含有錶面檔案的 Android App Bundle,請完成以下各節所列步驟。
宣告使用錶面格式
在新應用程式的資訊清單檔案 (AndroidManifest.xml
) 中,加入應用程式屬性,指明使用的是錶面格式:
<?xml version="1.0" encoding="utf-8" standalone="no"?> <manifest ...> <application ...> <property android:name="com.google.wear.watchface.format.version" android:value="1" /> </application> </manifest>
宣告錶面中繼資料
在應用程式的 res/xml
資源目錄中,建立名為 watch_face_info.xml
的新檔案。您可以在這個檔案中定義錶面中繼資料:
<?xml version="1.0" encoding="utf-8"?>
<WatchFaceInfo>
<!-- Only "Preview" is required. -->
<Preview value="@drawable/watch_face_preview" />
<Category value="CATEGORY_EMPTY" />
<AvailableInRetail value="true" />
<MultipleInstancesAllowed value="true" />
<Editable value="true" />
</WatchFaceInfo>
這個檔案中的欄位代表下列詳細資料:
Preview
- 用於參考內含錶面預覽圖片的可繪項目。
Category
用於定義錶面類別。必須是字串或字串的參照,例如
@string/ref_name
。每個裝置製造商都可以定義自己的錶面類別組合。預設值為
empty_category_meta
,可將這個錶面與錶面挑選器檢視畫面底部的其他「empty category」錶面分為同一組。AvailableInRetail
用於指出可否在裝置處於零售商展示模式時使用錶面。這必須是布林值,或是布林值的參照,例如
@bool/watch_face_available_in_retail
。預設值為
false
。MultipleInstancesAllowed
用於指出錶面是否可有多項常用工具。這必須是布林值,或是布林值的參照,例如
@bool/watch_face_multiple_instances_allowed
。預設值為
false
。Editable
用於指出錶面是否「可編輯」,可編輯的意思是錶面具有一項設定,或至少一個未固定的小工具。此屬性可用於在常用工具清單中顯示或隱藏錶面的「Edit」按鈕。
預設值為 false。
宣告錶面名稱
在應用程式的資訊清單檔案 (AndroidManifest.xml
) 中,將 android:label
屬性設為錶面名稱:
<application android:label="@string/watch_face_name" >
宣告支援的錶面形狀
在應用程式的 res/xml
資源目錄中,宣告支援的錶面形狀組合:
<WatchFaces>
<!-- The default shape is "CIRCLE". -->
<WatchFace shape="CIRCLE" width="300" height="300"
file="@raw/watchface"/>
<WatchFace shape="CIRCLE" width="450" height="450"
file="@raw/watchface_large_circle"/>
<WatchFace shape="RECTANGLE" width="380" height="400"
file="@raw/watchface_rectangle"/>
</WatchFaces>
宣告錶面詳細資料
依據您在宣告支援的錶面形狀時使用的 file
屬性值,在應用程式的 res/raw
資源目錄中建立相對應的檔案。您可以在這個檔案中,為每個錶面形狀定義錶面外觀和行為。
以本頁的範例來說,原始 XML 檔案會像這樣:
res/raw/watchface.xml
res/raw/watchface_large_circle.xml
res/raw/watchface_rectangle.xml
根元素一律為 WatchFace
:
<WatchFace width="450" height="450" shape="CIRCLE">
<!-- Remainder of your Watch Face Format definition here. -->
<!-- If this file defines a watch face for a circular device shape, place
resources used in this file in the "/res/drawable-nodpi" directory. -->
<!-- If this file defines a watch face for a rectangular or other
non-circular shape, place resources ued in this file in the
"/res/drawable-notround-nodpi" directory. -->
</WatchFace>
識別錶面發布商 (選用)
您可以選擇在應用程式的資訊清單檔案中宣告任意字串,此字串可用於識別錶面的發布商,或您目前所用的工具名稱和版本:
<application ...> ... <property android:name="com.google.wear.watchface.format.publisher" android:value="{toolName}-{toolVersion}" /> </application>
建構錶面的應用程式套件
如要建構包含錶面的 Android App Bundle,請使用 bundletool
。您也可以進一步瞭解如何使用 bundletool
建構應用程式。
請參閱 GitHub 範例,瞭解如何準備要發布的應用程式套件,以及在提交至 Google Play 前使用驗證工具檢查正確性。
為您推薦
- 注意:系統會在 JavaScript 關閉時顯示連結文字
- 顯示在應用程式「最近使用」和「繼續使用」裡
- 新增啟動畫面
- 與資訊方塊互動