简体   繁体   English

Android-Wear:手机的穿戴通知中的SpannableString

[英]Android-Wear: SpannableString in wear notifications from phone

I was wondering... 我在想...

I've been able to create a styled notification on my android-wearable-device (using spannable-strings) while implementing it on a wearable-based app. 在基于可穿戴的应用程序上实现它的同时,我已经能够在我的android-wearable-device(使用spannable-strings)上创建样式化通知。 (I used the SpannableStringBuilder class for that purpose). (我为此使用SpannableStringBuilder类)。

Now, Whenever you create styled notifications on a phone-based app (using SpannableStringBuilder), they will show up on the wearable-device, but without the special styling... 现在,每当您在基于电话的应用程序(使用SpannableStringBuilder)上创建样式通知时,它们都会显示在可穿戴设备上,但没有特殊样式...

Is there any way to achieve styled notifications on the wearable device with only a phone-based app? 仅使用基于电话的应用程序,有什么方法可以在可穿戴设备上实现样式通知吗?

Thanks. 谢谢。

Most styling effects applied to notifications created on an handheld device will show up on both wearable and handheld devices. 应用于手持设备上创建的通知的大多数样式效果将同时显示在可穿戴设备和手持设备上。

Styling effects that will show up on WEARABLE and HANDHELD devices : 将在WEARABLE和HANDHELD设备上显示的样式效果:

  • Color (ForegroundColorSpan) 颜色(ForegroundColorSpan)
  • Underline (UnderlineSpan) 下划线(UnderlineSpan)
  • Text style (StyleSpan) including : BOLD, ITALIC, BOLD_ITALIC 文字样式(StyleSpan),包括:BOLD,ITALIC,BOLD_ITALIC
  • Font family (TypeFaceSpan) 字体家族(TypeFaceSpan)
  • Subscript (SubscriptSpan) and superscript (SuperscriptSpan) 下标(SubscriptSpan)和上标(SuperscriptSpan)

Styling effects that will show up on HANDHELD devices ONLY : 仅在手持设备上显示的样式效果:

  • Text size (RelativeSizeSpan) 文字大小(RelativeSizeSpan)
  • Strikethrough (StrikethroughSpan) 删除线(StrikethroughSpan)

The styling should show up on both. 样式应同时出现在两者上。 I have done it using the SpannableStringBuilder class and NotificationCompat. 我已经使用SpannableStringBuilder类和NotificationCompat完成了它。

Please refer to our sample under samples/android-20-wearable/Notifications. 请参阅sample / android-20-wearable / Notifications下的示例。 Take a look inside NotificationPresets in the Application module. 在“应用程序”模块中查看NotificationPresets。 It contains a private static class StylizedTextNotificationPreset and the method buildNotifications contains the code for stylised notifications. 它包含一个私有静态类StylizedTextNotificationPreset,而方法buildNotifications包含风格化通知的代码。

One thing to note is color. 要注意的一件事是颜色。 In Holo, the default background is black whereas on Wear, the notification background is white. 在Holo中,默认背景为黑色,而在Wear中,通知背景为白色。 I find that colour tends to work well against one and not the other or vice versa so I would recommend using colour sparingly and maybe only stick to shades of grey. 我发现颜色往往可以很好地对抗一种颜色,而另一种则不能,反之亦然,因此我建议您尽量少使用颜色,并且最好只使用灰色阴影。 I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM