lightbulb_outline Please take our October 2018 developer survey. Start survey

Use 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 Wear UI 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 Wear UI 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:

Kotlin

import android.support.wear.widget.WearableRecyclerView
...
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.wearable_recycler_view_basic)
    findViewById<WearableRecyclerView>(R.id.wrv).apply {
        layoutManager = ChildLayoutManager()
        adapter = TestAdapter()
    }
}

Java

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:

Kotlin

import android.support.wear.widget.WearableRecyclerView
...
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.wearable_recycler_view_basic)
    findViewById<WearableRecyclerView>(R.id.wrv).apply {
        layoutManager = WearableLinearLayoutManager(this@MainActivity)
        adapter = TestAdapter()
    }
}

Java

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