コンテンツに移動

よくアクセスするページ

最近アクセスしたページ

navigation

Exiting Full-Screen Activities on Wear

A user can exit a Wear OS activity by swiping from left to right. If the app has horizontal scrolling (e.g., the type of scrolling available in an app containing maps), a user exits by navigating to the edge of the content and then swiping from left to right.

Pressing the power button returns the user to the watch face.

Refer to the following related resources:

The Swipe-To-Dismiss Gesture

Users swipe from left to right to close the current screen. Therefore, it is recommended that you utilize the following:

It also is recommended that your app does not contain horizontal swiping gestures.

Dismissal of an activity

An activity automatically supports swipe-to-dismiss. Swiping an activity from left to right results in dismissal of the activity, and the app navigates down the back stack.

Fragments

You can wrap a fragment-containing view in the SwipeDismissFrameLayout class, as follows:

public class SwipeDismissFragment extends Fragment {
  private final Callback mCallback =
    new Callback() {
      @Override
        public void onSwipeStart() {
          // optional
        }

        @Override
        public void onSwipeCancelled() {
          // optional
        }

        @Override
        public void onDismissed(SwipeDismissFrameLayout layout) {
          // Code here for custom behavior such as going up the
          // back stack and destroying the fragment but staying in the app.
        }
      };

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    SwipeDismissFrameLayout swipeLayout = new SwipeDismissFrameLayout(getActivity());

    // If the fragment should fill the screen (optional), then in the layout file,
    // in the android.support.wear.widget.SwipeDismissFrameLayout element,
    // set the android:layout_width and android:layout_height attributes
    // to "match_parent".

    View inflatedView = inflater.inflate(R.layout.swipe_dismiss_frame_layout, swipeLayout, false);
    swipeLayout.addView(inflatedView);
    swipeLayout.addCallback(mCallback);

    return swipeLayout;
    }
}

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

Horizontal scrollable views

In some cases, such as in a view containing a map that supports panning, the user interface would not prevent horizontal swiping. In this scenario, there are two choices:

To wrap a view in a SwipeDismissFrameLayout object, review the following examples:

XML for 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 me to dismiss me." />
</android.support.wear.widget.SwipeDismissFrameLayout>

Code snippet

SwipeDismissFrameLayout testLayout =
    (SwipeDismissFrameLayout) activity.findViewById(R.id.swipe_dismiss_root);
testLayout.addCallback(new SwipeDismissFrameLayout.Callback() {
    @Override
    public void onDismissed(SwipeDismissFrameLayout layout) {
        layout.setVisibility(View.GONE);
    }
  }
);

Generally not recommended: Disabling swipe-to-dismiss

Disabling swipe-to-dismiss generally is not recommended because the user expects to dismiss any screen with a swipe. In an exceptional case, you can extend the default theme (in a style resource) and set the android:windowSwipeToDismiss attribute to false:

<resources>
  <style name="AppTheme" parent="@android:style/Theme.DeviceDefault">
    <item name="android:windowSwipeToDismiss">false</item>
  </style>
</resources>

You can then inform users (on their first use of your app) that they can exit the app by pressing the power button.

Dismissal behavior before Wear 2.0

Before Wear 2.0, the DismissOverlayView class was used to implement the long-press for a user to dismiss an app. The DismissOverlayView class no longer should be used.

Additionally, long-pressing to dismiss an app is no longer suggested. Do not implement the long-press for dismissing full screen activities (panning or immersive activities such as Google Maps).

Dismissal via the Power Button

A press of the power (hardware) button sends a power key event. Therefore, you cannot use the power button as a back button or for navigation in general.

When pressed, the power button returns the user to the home screen (watch face). There are two exceptions:

Note that when the power button is pressed, the isFinishing() method of the Activity class does not return true (nor can you intercept the key event).

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