ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
การแจ้งเตือนล่วงหน้า
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การแจ้งเตือนคือข้อความที่ Android แสดงนอกแอปเพื่อแจ้งข้อมูลอัปเดต การช่วยเตือน และข้อมูลอื่นๆ ที่เหมาะกับเวลานั้นๆ ให้แก่ผู้ใช้ ในระบบปฏิบัติการ Android Automotive การแจ้งเตือนจะแสดงเป็นการแจ้งเตือนล่วงหน้า (HUN) หรือในแผงการแจ้งเตือน (หรือทั้ง 2 แบบ) หน้านี้จะอธิบายวิธีปรับแต่ง HUN

รูปที่ 1 การแจ้งเตือน
คุณสามารถปรับแต่ง HUN ได้ 2 วิธีด้วยการลบล้างค่าการกําหนดค่าที่ระบุไว้ด้านล่าง
เมื่อปรับแต่ง HUN โปรดตรวจสอบว่า HUN ได้รับผลกระทบจากลําดับชั้น Z ของแถบระบบอย่างไร หากลําดับ Z ของแถบระบบคือ 10 ขึ้นไป แถบดังกล่าวจะปรากฏอยู่ด้านบนของ HUN เช่น หาก HUN แสดงที่ด้านบนของหน้าจอและแถบระบบด้านบนมีลําดับ Z เป็น 10 แถบระบบด้านบนจะแสดงอยู่เหนือ HUNเว้นแต่จะมีการปรับแต่งตัวช่วยภาพเคลื่อนไหวของ HUN เพื่อถ่วงดุลตําแหน่งสุดท้ายของ HUN ตามความสูงของแถบระบบด้านบน
เอกสารประกอบที่เกี่ยวข้อง
config_showHeadsUpNotificationOnBottom
HUN สามารถแสดงที่ด้านบนหรือด้านล่างของหน้าจอโดยขึ้นอยู่กับค่าการกําหนดค่า config_showHeadsUpNotificationOnBottom
ค่านี้จะตั้งค่าตำแหน่งสุดท้ายของการแจ้งเตือนที่ด้านบนของหน้าจอ โดยค่าเริ่มต้นจะตั้งค่าเป็น 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 UTC
[[["เข้าใจง่าย","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 UTC"],[],[],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```"]]