Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
實作畫面導覽
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
應用程式通常會顯示多個不同畫面,每個畫面可能使用不同的範本,使用者與介面互動時可瀏覽這些畫面。
ScreenManager 類別提供螢幕堆疊,可用於推送螢幕,當使用者在車輛螢幕上選取「返回」按鈕,或使用部分車輛提供的硬體「返回」按鈕時,系統會自動彈出螢幕。
這段程式碼說明如何將返回動作新增至訊息範本,以及在使用者選取時推送新畫面的動作:
val header = Header.Builder()
.setStartHeaderAction(Action.BACK)
.build()
val template = MessageTemplate.Builder("Hello world!")
.setHeader(header)
.addAction(
Action.Builder()
.setTitle("Next screen")
.setOnClickListener { screenManager.push(NextScreen(carContext)) }
.build()
)
.build()
Action.BACK 物件是標準的 Action,會自動叫用 ScreenManager.pop。您可以使用 CarContext 提供的 OnBackPressedDispatcher 例項覆寫這項行為。
為確保行車安全,螢幕堆疊最多只能包含五個畫面。詳情請參閱「範本限制」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2026-06-30 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2026-06-30 (世界標準時間)。"],[],[]]