Android Wear通知布局 - 窥视和环境中的两行

时间:2016-07-06 20:18:53

标签: android android-notifications wear-os android-wear-notification

我注意到天气时间线(例如)在窥视和环境中显示两条线路的通知。我想根据我的要求复制这个,但我无法这样做。我尝试过InboxStyle和BigTextStyle无济于事。图标位置也不同,可以显示更多标题。

这可能是某种方式,还是因为天气时间线是一个穿着应用"?

wear_notify

        NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("TestTitle")
                    .setContentText("TestContextTextLoremIpsum");

1 个答案:

答案 0 :(得分:0)

通知卡可能会覆盖屏幕的重要部分,具体取决于system UI style。通过确保用户在通知卡存在时仍能告知时间,您的表盘应适应这些情况。

您需要确定偷看卡上方的可用空间,以便调整您的表盘,使用WatchFaceService.Engine.getPeekCardPosition()方法。这提供了它在底部偷看并允许表面暴露时的位置。

监视面不应干扰系统UI元素,如Accommodate System UI Elements中所述。如果您的表盘背景较浅或在屏幕底部附近显示信息,您可能需要配置通知卡的大小或启用背景保护。

@Override
public void onCreate(SurfaceHolder holder) {
super.onCreate(holder);

// configure the system UI
setWatchFaceStyle(new WatchFaceStyle.Builder(AnalogWatchFaceService.this)
.setCardPeekMode(WatchFaceStyle.PEEK_MODE_SHORT)
.setBackgroundVisibility(WatchFaceStyle
.BACKGROUND_VISIBILITY_INTERRUPTIVE)
.setShowSystemUiTime(false)
.build());
...
}

上面的代码片段将偷看卡配置为单行高,偷看卡的背景仅短暂显示,仅用于中断通知,系统时间不显示。