自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
浮动通知
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通知是指 Android 在应用之外显示的消息,旨在向用户提供更新、提醒或其他实时信息。在 Android Automotive OS 中,通知可以显示为浮动通知 (HUN) 或显示在“通知”面板中,或同时以这两种方式显示。本页面介绍了如何自定义 HUN。

图 1. 通知
替换下面详述的配置值后,您可以通过两种方式自定义 HUN:
自定义 HUN 时,务必确定它受系统栏 Z 轴顺序影响的方式。如果系统栏的 Z 轴顺序为 10 或更高,它就会显示在 HUN 上方。例如,如果 HUN 显示在屏幕顶部,且顶部系统栏的 Z 轴顺序为 10,顶部系统栏就会显示在 HUN 上方,除非系统将 HUN 动画帮助程序自定义为使 HUN 的最终位置偏移顶部系统栏的高度。
相关文档
config_showHeadsUpNotificationOnBottom
可以根据配置值 config_showHeadsUpNotificationOnBottom
在屏幕顶部或底部显示 HUN。此值默认设置为 false
。通过此值,可将通知的最终位置设置在屏幕顶部。

图 2. 默认 HUN
config_headsUpNotificationAnimationHelper
通知可通过多种方式在屏幕上显示和退出屏幕。系统提供了一组默认 Animator 辅助程序类,用户可以通过替换 config_headsUpNotificationAnimationHelper
来关闭此组辅助程序类。
com.android.car.notification.headsup.animationhelper.CarHeadsUpNotificationTopAnimationHelper
为 HUN 添加动画效果,使其从初始位置向下移至最终位置,然后变为可见状态,最后变为不可见状态。

图 3. 顶部动画辅助程序
com.android.car.notification.headsup.animationhelper.CarHeadsUpNotificationBottomAnimationHelper
为 HUN 添加动画效果,使其从初始位置移至最终位置,然后变为可见状态,最后变为不可见状态。

图 4. 底部动画辅助程序
com.android.car.notification.headsup.animationhelper.CarHeadsUpNotificationRightAnimationHelper
为 HUN 添加动画效果,使其从初始位置向左移至最终位置,然后变为可见状态,最后变为不可见状态。
图 5. 右侧动画辅助程序
自定义动画辅助程序
如需进行额外的自定义,可以替换 Animator 辅助程序类,也可以使用自定义 Animator 辅助程序类,前提是该辅助类实现了如下代码段中所示的 HeadsUpNotificationAnimationHelper
接口:
[...]
public class SampleAnimationHelper implements
HeadsUpNotificationAnimationHelper {
@Override
public AnimatorSet getAnimateInAnimator(Context context, View view) {
return (AnimatorSet) AnimatorInflater.loadAnimator(
context, R.animator.heads_up_notification_transition_in);
}
@Override
public AnimatorSet getAnimateOutAnimator(Context context, View view) {
return (AnimatorSet) AnimatorInflater.loadAnimator(
context, R.animator.heads_up_notification_transition_out);
}
@Override
public void resetHUNPosition(View view) {
view.setY(-1 * view.getHeight());
view.setAlpha(0);
}
}
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Heads-up notifications\n\nA *notification* is a message that Android displays outside an app to provide\nupdates, reminders, and other timely information to users. In the Android Automotive OS, a\nnotification can be displayed either as a *heads-up notification (HUN)* or in the\nNotification panel (or in both). This page explains how to customize HUNs.\n\n**Figure 1.** Notification\n\nBy overriding the configuration values detailed below, you can customize HUNs in two ways:\n\n- Position\n- Animation\n\nWhen customizing a HUN, be sure to determine how it is affected by the Z-order\nof system bars. If the Z-order of a system bar is 10 or higher, it appears on top of\nthe HUNs. For example, if the HUN is displayed at the top of the screen and the top\nsystem bar has a Z-order of 10, the top system bar is displayed on top of the HUN\n*unless* the HUN animation helper is customized to offset the final position of\nthe HUN by the height of the top system bar.\n\nRelated documentation\n---------------------\n\n- To learn how and why to overlay resources, see\n [Overlays](/docs/core/architecture/rros)\n in Customizing System UI.\n\n- To learn more about notifications, see\n [Notifications on Android Automotive OS](https://developer.android.com/training/cars/notifications)\n on developer.android.com.\n\nconfig_showHeadsUpNotificationOnBottom\n--------------------------------------\n\nA HUN can be displayed either on the top or bottom of the screen based\non the configuration value `config_showHeadsUpNotificationOnBottom`.\nSet to `false` by default, this value sets the final position of the\nnotification at the *top* of the screen.\n\n**Figure 2.** Default HUN\n\nconfig_headsUpNotificationAnimationHelper\n-----------------------------------------\n\nThere are multiple ways of how the notification should appear on screen and\nleave the screen. A set of default animator helper classes are provided and can\nbe switched out by overriding `config_headsUpNotificationAnimationHelper`.\n\n#### com.android.car.notification.headsup.animationhelper.CarHeadsUpNotificationTopAnimationHelper\n\nAnimates the HUN to transition from the initial position, down to the final position,\nto visible, and then to invisible.\n\n**Figure 3.** Top Animation Helper\n\n#### com.android.car.notification.headsup.animationhelper.CarHeadsUpNotificationBottomAnimationHelper\n\nAnimates the HUN to transition from the initial position, to the final position,\nto visible, and then to invisible.\n\n**Figure 4.** Bottom Animation Helper\n\n#### com.android.car.notification.headsup.animationhelper.CarHeadsUpNotificationRightAnimationHelper\n\nAnimates the HUN to transition from the initial position left, to the\nfinal position, to visible, and then to invisible.\n\n|---|---|\n| | |\n\n**Figure 5.** Right Animation Helper\n\n#### Custom animation helper\n\nShould additional customization be required, the animator helper\nclasses can be overridden or a custom animator helper class can be used\nprovided the help class implements the `HeadsUpNotificationAnimationHelper`\ninterface as shown in this code snippet: \n\n```ini\n[...]\n\npublic class SampleAnimationHelper implements\n HeadsUpNotificationAnimationHelper {\n\n @Override\n public AnimatorSet getAnimateInAnimator(Context context, View view) {\n return (AnimatorSet) AnimatorInflater.loadAnimator(\n context, R.animator.heads_up_notification_transition_in);\n }\n\n @Override\n public AnimatorSet getAnimateOutAnimator(Context context, View view) {\n return (AnimatorSet) AnimatorInflater.loadAnimator(\n context, R.animator.heads_up_notification_transition_out);\n }\n\n @Override\n public void resetHUNPosition(View view) {\n view.setY(-1 * view.getHeight());\n view.setAlpha(0);\n }\n}\n```"]]