コンテンツに移動

よくアクセスするページ

最近アクセスしたページ

navigation

Using the Wear UI Library

Android support libraries enable consistent, optimized user interfaces across apps. The Android Support Library includes the Wear UI Library, which contains many of the preferred UI components for your Wear OS apps.

The Wear UI Library includes (but is not limited to) the following classes. Some of the classes have similar names to, and offer several benefits over, the related deprecated classes in the Wearable Support Library:

Also see Action and Navigation Drawers in the Wear UI Library.

Add a Dependency on the Android Support Library

To use the Wear UI Library, add the following dependency in your Wear module's build.gradle file:

dependencies {
    ...
    compile 'com.android.support:wear:27.0.0'
}

If necessary, include a dependency on the Wearable Support Library (see Creating or Updating a Project). Also see Adding Support Libraries.

Import Classes from the Wear UI Library Package

When you use a class from the Wear UI Library, import that class from the android.support.wear.widget package. See the Example of Using a Library Class.

Use the Right Element Names in Layout Files

In layout files, use fully qualified names that correspond to the Wear UI Library (rather than to the Wearable Support Library).

For example, to use the SwipeDismissFrameLayout class from the Wear UI Library, you could specify the following in a layout file:

<android.support.wear.widget.SwipeDismissFrameLayout
    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." />
</android.support.wear.widget.SwipeDismissFrameLayout>

Example of Using a Library Class

The classes in the Wear UI Library have functionality that is the same or similar to that in the Wearable Support Library. Some class, method, and attribute names are updated to improve consistency with the Android Support Library.

For example, an activity that uses the WearableRecyclerView class from the Wearable Support Library could include the following code:

import android.support.wearable.view.WearableRecyclerView;
...
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wearable_recycler_view_basic);
    WearableRecyclerView wrv = findViewById(R.id.wrv);
    wrv.setLayoutManager(new ChildLayoutManager());
    wrv.setAdapter(new TestAdapter());
}

Similarly, an activity that uses the WearableRecyclerView class from the Wear UI Library could include the following code. Differences from the above code are in bold:

import android.support.wear.widget.WearableRecyclerView;
...
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wearable_recycler_view_basic);
    WearableRecyclerView wrv = findViewById(R.id.wrv);
    wrv.setLayoutManager(new WearableLinearLayoutManager(this));
    wrv.setAdapter(new TestAdapter());
}

Action and Navigation Drawers in the Wear UI Library

The Wear UI Library has components for action and navigation drawers.

For additional information, see Wear Navigation and Actions.

Replacements for Deprecated Classes

The table below contains replacements, in the Wear UI Library and elsewhere, for deprecated classes in the Wearable Support Library.

Deprecated class Replacement information
ActionChooserView AlertDialog
ActionLabel Use WearableActionDrawerView for navigation and ConfirmationOverlay for confirmation actions.
ActionPage Use WearableActionDrawerView for navigation and ConfirmationOverlay for confirmation actions.
BoxInsetLayout BoxInsetLayout
BoxInsetLayout.LayoutParams BoxInsetLayout.LayoutParams
CardFragment Use SnapHelper and a RecyclerView.
CardFrame Use SnapHelper and a RecyclerView.
CardScrollView Use SnapHelper and a RecyclerView.
CircledImageView RoundedDrawable
CircularButton See Material design library components.
CrossfadeDrawable AnimationSet
CurvedChildLayoutManager WearableLinearLayoutManager
DefaultOffsettingHelper WearableLinearLayoutManager
DelayedConfirmationView CircularProgressLayout
DismissOverlayView Not applicable; long-pressing to dismiss an app is no longer suggested for immersive activities.
DotsPageIndicator Not applicable; horizontal scrolling is no longer encouraged for apps.
FragmentGridPagerAdapter Use PageSnapHelper and a RecyclerView.
GridPagerAdapter Use SnapHelper and a RecyclerView.
GridViewPager Use SnapHelper and a RecyclerView.
GridViewPager.LayoutParams Not applicable; bi-directional spatial models are no longer encouraged for apps. If you are implementing a vertical paging pattern, consider using the SnapHelper and a RecyclerView.
ProgressSpinner ProgressBar
SwipeDismissFrameLayout SwipeDismissFrameLayout
SwipeDismissFrameLayout.Callback SwipeDismissFrameLayout.Callback
WatchViewStub See Providing Resources.
WearableFrameLayout See Providing Resources.
WearableFrameLayout.LayoutParams See Providing Resources.
WearableListView WearableRecyclerView
WearableListView.Adapter For centering and snapping list items, consider using the WearableRecyclerView, supported by a SnapHelper or a LinearSnapHelper. For scaling and otherwise modifying the list items based on their location on the screen, consider using a WearableLinearLayoutManager or a CurvingLayoutCallback.
WearableListView.GenericAdapter For centering and snapping list items, consider using the WearableRecyclerView, supported by a SnapHelper or a LinearSnapHelper. For scaling and otherwise modifying the list items based on their location on the screen, consider using a WearableLinearLayoutManager or a CurvingLayoutCallback.
WearableListView.ViewHolder For centering and snapping list items, consider using the WearableRecyclerView, supported by a SnapHelper or a LinearSnapHelper. For scaling and otherwise modifying the list items based on their location on the screen, consider using a WearableLinearLayoutManager or a CurvingLayoutCallback.
WearableRecyclerView WearableRecyclerView
WearableRecyclerView.ChildLayoutManager WearableLinearLayoutManager
WearableRecyclerView.OffsettingHelper WearableLinearLayoutManager.LayoutCallback
WearableActionDrawer WearableActionDrawerView
WearableDrawerLayout WearableDrawerLayout
WearableDrawerLayout.DrawerStateCallback WearableDrawerLayout.DrawerStateCallback
WearableDrawerView WearableDrawerView
WearableNavigationDrawer WearableNavigationDrawerView
WearableNavigationDrawer.WearableNavigationDrawerAdapter WearableNavigationDrawerView.WearableNavigationDrawerAdapter
このサイトでは、ユーザーが選択したサイトの言語と表示設定を保存する目的で Cookie を使用しています。

Android デベロッパー向けの最新情報やヒントを入手して、Google Play での成功を手に入れましょう。

* 必須

送信しました

WeChat で Google Developers をフォローする

このサイトをで表示しますか?

ページの表示言語としてを選択しましたが、このサイトの言語はに設定されています。

言語設定を変更してこのサイトをで表示しますか?言語設定を変更する場合は、各ページの下にある言語メニューを使用してください。

このクラスには、API レベル 以上が必要です。

API レベル が選択されているため、このドキュメントは非表示になっています。左のナビゲーションの上にあるセレクタを使って、ドキュメントの API レベルを変更できます。

アプリに必要な API レベルを指定する方法について、詳しくは異なるプラットフォーム バージョンのサポートをご覧ください。

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)