Android Jetpack 包含 Wear OS UI 程式庫。Wear OS UI 程式庫包含 (但不限於) 下列類別:
-
CurvedTextView
。一個方便您根據視圖中最大的圓形大小建立弧形文字的元件。 -
DismissibleFrameLayout
。這個版面配置可讓使用者透過按下返回按鈕或在螢幕上由左向右滑動來關閉任何檢視畫面。Wear OS 使用者應為由左向右滑動,以便執行返回動作。 -
WearableRecyclerView
。提供透過WearableLinearLayoutManager
更新子版面配置的基本偏移邏輯的檢視畫面。 -
AmbientModeSupport
。與AmbientModeSupport.AmbientCallbackProvider
介面搭配使用的類別,以提供支援微光模式。
如需完整清單,請參閱「版本資訊」。
新增 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>