自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
抬頭通知
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
通知是 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
通知在螢幕上顯示和離開螢幕的方式有多種。系統會提供一組預設的動畫輔助類別,您可以透過覆寫 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. 右側動畫輔助工具
自訂動畫輔助工具
如果需要進一步自訂,您可以覆寫動畫輔助程式類別,或是使用自訂的動畫輔助程式類別,前提是輔助類別實作 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 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間: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```"]]