Langsung ke konten

Paling sering dikunjungi

Terakhir dikunjungi

navigation

Addressing Common Issues on Wear

Creating a custom watch face for Wear OS by Google is substantially different from creating notifications and wearable-specific activities. This class shows you how to resolve some issues that you may encounter as you implement your first few watch faces.

Refer to the following related resources:

Detect the shape of the screen

Some Wear OS devices have square screens, while others have round screens. Devices with round screens can contain an inset (or "chin") at the bottom of the screen. Your watch face should adapt to and take advantage of the particular shape of the screen, as described in the design guidelines.

Wear OS lets your watch face determine the screen shape at runtime. To detect whether the screen is square or round, override the onApplyWindowInsets() method in the CanvasWatchFaceService.Engine class as follows:

private class Engine extends CanvasWatchFaceService.Engine {
    boolean mIsRound;
    int mChinSize;

    @Override
    public void onApplyWindowInsets(WindowInsets insets) {
        super.onApplyWindowInsets(insets);
        mIsRound = insets.isRound();
        mChinSize = insets.getSystemWindowInsetBottom();
    }
    ...
}

To adapt your design when you draw your watch face, check the value of the mIsRound and mChinSize member variables.

Accommodate peek cards

Note: Peek cards only appear in Wear 1.x apps.

When users receive a notification, the notification card may cover a significant portion of the screen, depending on the system UI style. Your watch face should adapt to these situations by ensuring that users can still tell the time while the notification card is present.

Analog watch faces can make adjustments when a notification card is present, like scaling down the watch face to fit inside the portion of the screen not covered by the peek card. Digital watch faces that display the time in the area of the screen not covered by peek cards do not usually require adjustments. To determine the free space above the peek card so you can adapt your watch face, use the WatchFaceService.Engine.getPeekCardPosition() method.

In ambient mode, peek cards have a transparent background. If your watch face contains details near the card in ambient mode, consider drawing a black rectangle over them to ensure that users can read the contents of the card.

Configure the system indicators

To ensure that the system indicators remain visible, you can configure their position on the screen and whether they need background protection when you create a WatchFaceStyle instance:

For more information about the system indicators, see Configure the System UI and read the design guidelines.

Use relative measurements

Wear OS devices from different manufacturers feature screens with a variety of sizes and resolutions. Your watch face should adapt to these variations by using relative measurements instead of absolute pixel values.

When you draw your watch face, obtain the size of the canvas with the Canvas.getWidth() and Canvas.getHeight() methods and set the positions of your graphic elements using values that are some fraction of the detected screen size. If you resize the elements of your watch face in response to a peek card, use values that are some fraction of the remaining space above the card to redraw your watch face.

Situs ini menggunakan cookies untuk menyimpan preferensi Anda tentang bahasa di situs tertentu dan opsi tampilan.

Dapatkan berita dan tips terbaru dari developer Android yang akan membantu Anda mencapai kesuksesan di Google Play.

* Wajib Diisi

Hore!

Ikuti Google Developers di WeChat

Buka situs ini dalam bahasa ?

Anda meminta halaman dalam bahasa , namun preferensi bahasa untuk situs ini adalah .

Ingin mengubah preferensi bahasa dan mengakses situs ini dalam bahasa ? Jika nanti Anda ingin mengubah preferensi bahasa, gunakan menu bahasa di bagian bawah setiap halaman.

Kelas ini memerlukan tingkat API atau yang lebih tinggi

Dokumen ini tersembunyi karena level API yang Anda pilih untuk dokumentasi ini adalah . Anda dapat mengubah level API dokumentasi dengan pemilih di atas menu navigasi sebelah kiri.

Untuk informasi lebih lanjut tentang menentukan level API yang diperlukan aplikasi Anda, baca Mendukung Versi Platform Yang Berbeda.

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