コンテンツに移動

よくアクセスするページ

最近アクセスしたページ

navigation

Using Wrist Gestures on Wear

Wrist gestures can enable quick, one-handed interactions with your app when a touch screen is inconvenient.

For example, a user can scroll through notifications with one hand while holding a cup of water with the other. Examples that show the use of wrist gestures also include:

To review the wrist gestures on your watch, confirm gestures are turned on by selecting Settings > Gestures > Wrist Gestures On. Then complete the Gestures tutorial on the watch (Settings > Gestures > Launch Tutorial).

The following gesture from the Wear OS Help is unavailable to apps:

Wrist gestures can be used in these ways:

Each wrist gesture is mapped to an int constant from the KeyEvent class, as shown in the following table:

Gesture KeyEvent Description
Flick wrist out KEYCODE_NAVIGATE_NEXT This key code goes to the next item.
Flick wrist in KEYCODE_NAVIGATE_PREVIOUS This key code goes to the previous item.

Using a Curved Layout to Support Wrist Gestures

The WearableRecyclerView class provides a curved layout for lists and automatically supports wrist gestures. The class has predefined actions for occurrences of wrist gestures when the View has the focus. For information about using the WearableRecyclerView class, see Creating Lists. Also see Best Practices.

Note: The WearableRecyclerView class replaces a similar, deprecated class in the Wearable Support Library.

Even if you use a WearableRecyclerView, you may want to use constants from the KeyEvent class. The predefined actions can be overridden by subclassing the WearableRecyclerView and re-implementing the onKeyDown() callback. The behavior can be disabled entirely by using setEnableGestureNavigation(false). Also see Handling Keyboard Actions.

Using Key Events Directly

You can use key events outside of a WearableRecyclerView to trigger new actions in response to gesture events. Importantly, these gesture events:

Specifically, these events are delivered to the top Activity, to the View with keyboard focus. Just as any other key event, a class that relates to user interaction (such as a View or an Activity) that implements KeyEvent.Callback can listen to key events that relate to wrist gestures. The Android framework calls the View or Activity that has the focus with the key events; for gestures, the onKeyDown() method callback is called when gestures occur.

As an example, an app may override predefined actions in a View or Activity (both implementing KeyEvent.Callback) as follows:

public final class GesturesActivity extends Activity {

 @Override /* KeyEvent.Callback */
 public boolean onKeyDown(int keyCode, KeyEvent event) {
  switch (keyCode) {
   case KeyEvent.KEYCODE_NAVIGATE_NEXT:
    // Do something that advances a user View to the next item in an ordered list.
    return moveToNextItem();
   case KeyEvent.KEYCODE_NAVIGATE_PREVIOUS:
    // Do something that advances a user View to the previous item in an ordered list.
    return moveToPreviousItem();
  }
  // If you did not handle it, let it be handled by the next possible element as deemed by the Activity.
  return super.onKeyDown(keyCode, event);
 }

 /** Shows the next item in the custom list. */
 private boolean moveToNextItem() {
  boolean handled = false;
  …
  // Return true if handled successfully, otherwise return false.
  return handled;
 }

 /** Shows the previous item in the custom list. */
 private boolean moveToPreviousItem() {
  boolean handled = false;
  …
  // Return true if handled successfully, otherwise return false.
  return handled;
 }
}

Best Practices

このサイトでは、ユーザーが選択したサイトの言語と表示設定を保存する目的で 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)