在 Wear OS 上建構以檢視畫面為基礎的使用者介面

Android Jetpack 包含 Wear OS UI 程式庫。Wear OS UI 程式庫包含下列類別:

如需完整清單,請參閱「版本資訊」。

新增 Wear OS UI 程式庫的依附元件

如要開始建立應用程式,請建立 Wear-OS 專屬專案。然後在應用程式的 build.gradle 檔案中新增下列依附元件:

dependencies {
    ...
  // Standard Wear OS libraries
  implementation "androidx.wear:wear:1.2.0"
  // includes support for wearable specific inputs
  implementation "androidx.wear:wear-input:1.1.0"
}

從 Wear OS UI 程式庫套件匯入類別

如要使用 Wear OS UI 程式庫中的類別,請從 androidx.wear.widget 套件匯入該類別。

在版面配置檔案中使用正確的元素名稱

在版面配置檔案中,使用與 Wear OS UI 程式庫相對應的完整名稱。

舉例來說,如要使用 Wear OS UI 程式庫中的 DismissibleFrameLayout 類別,您可以在版面配置檔案中指定以下內容:

<androidx.wear.widget.DismissibleFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/swipe_dismiss_root" >

    <TextView
        android:id="@+id/test_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="Swipe the screen to dismiss me." />
</androidx.wear.widget.DismissibleFrameLayout>