【问题标题】:Transparent notification background in AndroidAndroid中的透明通知背景
【发布时间】:2015-07-26 17:43:09
【问题描述】:

我想创建具有透明背景的 Android 通知。我正在使用 bigContent 和 remoteViews 来创建我自己的布局,但是当我将主布局的背景颜色设置为 @android/color/transparent 时,什么也没有发生。我仍然看到通知的标准白色背景。

如何在 Android 通知上设置透明背景? 我注意到我不是指通知栏(或状态栏),而是自定义通知的背景。

【问题讨论】:

  • 您确定“标准白色背景”不是来自通知托盘本身吗?
  • 是的,我确定 ;) 我创建了具有透明背景 xml 布局的 remoteViews,但通知看起来像是我的布局后面的“东西”,我不知道如何更改这个“东西”的颜色: D
  • “是的,我确定”——您是如何确定这一点的?除非您正在编写自己的自定义 ROM 并将您的应用程序限制为该自定义 ROM,否则您无法控制通知托盘的行为。通知托盘的外观和工作方式取决于 ROM 开发人员(通常是设备制造商)。
  • 我认为我们并不了解对方。使用 remoteViews 我可以创建自定义通知布局。在这个布局中,我想设置透明背景。但是当我运行我的应用程序时,该通知的背景不是透明的,而是白色的。
  • “第一个通知具有透明背景”——如果您的意思是四天的天气预报,我不知道这是 Notification 还是该设备通知托盘的功能。您需要在您的某些设备上安装该应用程序,查看通知托盘中是否显示该四天预报,然后查看背景是否为白色。如果四天预报没有出现,那么您的屏幕截图只显示了一个Notification。如果它出现但有白色背景,那可能是您设备的通知托盘背景。

标签: android notifications android-remoteview


【解决方案1】:

正如 CommonsWare 在 cmets 中所说,这是不可能的。

除非手机制造商进行更改(这很可能是不允许的),否则通知是分层构建的。底层是背景视图,它在棒棒糖上有一个灰色的颜色(不记得我最喜欢的棒棒糖)在背景视图的顶部你有通知提供的内容视图(你可以制作的视图)。当您使视图透明时,您会显示背景。你不能改变背景。

在棒棒糖上,这些是默认值:

<color name="notification_legacy_background_color">#ff1a1a1a</color>

<!-- The color of the material notification background -->
<color name="notification_material_background_color">#fffafafa</color>

<!-- The color of the material notification background when dimmed -->
<color name="notification_material_background_dimmed_color">#d4ffffff</color>

 <!-- The color of the material notification background when low priority -->
<color name="notification_material_background_low_priority_color">#ffe0e0e0</color>

<!-- The color of the material notification background for media notifications when no custom
     color is specified -->
<color name="notification_material_background_media_default_color">#ff424242</color>

更多信息: http://androidxref.com/5.1.1_r6/xref/frameworks/base/packages/SystemUI/res/values/colors.xml#80

http://androidxref.com/5.1.1_r6/xref/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java

【讨论】:

  • “除非手机制造商改变(这很可能是不允许的)”——在 Nexus 系列设备之外,任何其他主要制造商的设备通常会改变通知托盘的外观和感觉AOSP 中有什么。而且,我在兼容性定义文档中没有看到任何可以排除这种情况的内容。
  • 谢谢。现在我知道我不能这样做;)
  • 你说得对 CommonsWare,只需阅读兼容性文档,那里没有说您不能自定义体验。
猜你喜欢
  • 2018-12-20
  • 2016-12-02
  • 2011-08-08
  • 2015-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多