Wear OS에서 뷰 기반 UI 빌드

Compose 방식 사용해 보기
Wear OS용 Jetpack Compose는 Wear OS에 권장되는 UI 도구 키트입니다.

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.4.0"
  // includes support for wearable specific inputs
  implementation "androidx.wear:wear-input:1.2.0"
}

Wear OS UI 라이브러리 패키지에서 클래스 가져오기

Wear OS UI 라이브러리의 UI 구성요소를 사용하려면 androidx.wear.widget 패키지에서 가져오거나 대기 모드 지원을 위해 androidx.wear.ambient에서 가져옵니다.

레이아웃 파일에서 올바른 요소 이름 사용

레이아웃 파일에서 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>