Skip to content

Most visited

Recently visited

navigation

Using the Wear UI Library

Android support libraries enable consistent, optimized user interfaces across apps. Starting with the 26.0.0 Beta1 revision of the Android Support Library, you can use the Wear UI Library in your user interfaces.

The Wear UI Library includes the following classes, which have the same names and benefits as older classes in the existing Wearable Support Library:

Add a Dependency on the Android Support Library

The Wear UI Library is delivered with the Android Support Library. For a release timeline that includes the Android Support Library, see the schedule for the O Developer Preview.

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

dependencies {
    ...
    compile 'com.android.support:wear:26.0.0-beta1'
}

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());
}
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.