【问题标题】:Can't add page to Android Wear notification without the card background没有卡片背景,无法将页面添加到 Android Wear 通知
【发布时间】:2014-08-20 18:13:48
【问题描述】:

Android Wear 很可能不支持此功能,但似乎应该有一些解决方法。我想在通知中添加自定义第二页,但我不希望它具有白卡背景。

以下是我创建通知的方式:

Intent secondPageIntent = new Intent(this, SecondPageActivity.class);
PendingIntent secondPagePendingIntent = PendingIntent.getActivity(this, 0, secondPageIntent, 0);


Notification secondPageNotification = new NotificationCompat.Builder(this)
                        .extend(new NotificationCompat.WearableExtender()
                                        .setDisplayIntent(secondPagePendingIntent)
                                        .setHintShowBackgroundOnly(true)
                        )
                        .build();

Intent firstPageIntent = new Intent(this, FirstPageActivity.class);
PendingIntent firstPagePendingIntent = PendingIntent.getActivity(this, 0, firstPageIntent, PendingIntent.FLAG_UPDATE_CURRENT);


NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .extend(new NotificationCompat.WearableExtender()
                                        .setDisplayIntent(firstPagePendingIntent)
                                        .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.background))
                                        .addPage(secondPageNotification)
                        );


NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
                notificationManager.notify(curNotificationId++, builder.build());

我试过了:

  1. 设置 setHintShowBackgroundOnly 什么都不做
  2. 在 SecondPageActivity 中,尝试获取 parentActivity 并将其 alpha 设置为 0。不起作用,parentActivity 为 null。
  3. 调用 setCustomContentHeight(0) 不会移除卡片,它只会变瘦
  4. 我尝试不使用第二个页面,而是在用户滑动时启动一个活动,但它看起来不太好

我真的不知道接下来要尝试什么。我是一位经验丰富的工程师,但对 Android 还是很陌生。任何想法或建议都会有所帮助。

谢谢!

【问题讨论】:

  • 你在下面看到我的回答了吗?如果它对你有用,你能给我任何反馈吗?

标签: android-ui wear-os


【解决方案1】:

如果你想摆脱你必须设置的白卡

setCustomSizePreset(WearableExtender.SIZE_FULL_SCREEN)


所以不要这样:

您的自定义内容将出现在整个屏幕上(没有卡片装饰)。

请注意,您的自定义活动的背景是由清单中声明的​​样式定义的。不幸的是,任何具有透明背景的主题都无法使用,因此背景需要是不透明的:(

这是作为问题提交的:https://code.google.com/p/android/issues/detail?id=73900
我真的希望他们将来允许透明背景:\

【讨论】:

  • 谢谢,虽然透明度问题是个问题:/希望他们能尽快解决这个问题。
  • 是否可以将 ViewPager 作为活动内容?不过,我的回答不错 +1
  • 由于手势相关的限制(滑动),我怀疑它能否正常工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-25
  • 1970-01-01
  • 2021-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多