4

I'm making a watchface for Android Wear. I would like to position the status bar at the bottom instead of at the top.

The documentation states to use the setStatusBarGravity()-method of WatchFaceStyle.Builder: https://developer.android.com/reference/android/support/wearable/watchface/WatchFaceStyle.Builder.html#setStatusBarGravity(int)

However, this does not seem to work as intended. Whenever I use Gravity.BOTTOM, the icons are centered vertically inside the watchface instead of positioned at the bottom.

This is the code I use:

setWatchFaceStyle(new WatchFaceStyle.Builder(Watchface.this)
                .setShowUnreadCountIndicator(true)
                .setStatusBarGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)
                .setAcceptsTapEvents(true)
                .build());

Which results in this (notice the charging indicator in the middle)

img

What am I doing wrong? I have googled and SO'd, but couldn't find any relevant information.

Mavamaarten
  • 1,959
  • 18
  • 19

2 Answers2

2

What you're seeing, I'm afraid, is the Gravity.BOTTOM position. The placement of status bar icons is very generic, and the bottom alignment is just slightly below the actual vertical center, whereas Gravity.CENTER_VERTICAL is roughly one third of the screen.

Here's a breakdown of the placement of the icons for the three gravity values:

Gravity values for Wear OS

Bear in mind that circular screens do not respect the horizontal gravity value.

I know this is frustrating, but this is the way it is, I'm afraid. I'd suggest filing an issue at b.android.com to have this behavior changed.

Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
  • Incidentally, I believe this behavior is a remnant of the now obsolete peeking notifications from Android Wear 1.0. Originally, watch faces could allow notification cards to peek from the bottom of the screen. The system icons could as a result not be aligned to the bottom of the screen. Now that [`setAmbientPeekMode()`](https://developer.android.com/reference/android/support/wearable/watchface/WatchFaceStyle.Builder#setambientpeekmode) has been removed, I'm hoping the icon positions can be controlled with more granularity soon. – Paul Lammertsma Jan 30 '19 at 13:23
-2

Make sure that there are no spaces between the vertical bar separator and the Gravity constants because that will be perceived by the compiler as multiple parameters rather than one single “unified” Gravity concatenation parameter.

See "Building Your Watch Face: Using .setWatchFaceStyle()" in this documentation for more information.

Teyam
  • 7,686
  • 3
  • 15
  • 22
  • That's something I've never heard before. The pipe character is just a bitwise OR, which combines the Gravity constants into one integer, right? Anyways, I tried it, and it didn't work. Which is what I expected because I also tried Gravity.BOTTOM without Gravity.CENTER_HORIZONTAL. Thank you for the input, though! Any help is appreciated. – Mavamaarten May 24 '17 at 12:52