Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Navigation 3 là một thư viện điều hướng mới được thiết kế để hoạt động với Compose. Với Navigation 3, bạn có toàn quyền kiểm soát ngăn xếp lui và việc điều hướng đến và từ các đích đến cũng đơn giản như việc thêm và xoá các mục khỏi danh sách. Thư viện này tạo ra một hệ thống điều hướng ứng dụng linh hoạt bằng cách cung cấp:
Quy ước để lập mô hình ngăn xếp lui, trong đó mỗi mục trên ngăn xếp lui đại diện cho nội dung mà người dùng đã điều hướng đến
Giao diện người dùng tự động cập nhật theo các thay đổi trong ngăn xếp lui (bao gồm cả ảnh động)
Phạm vi cho các mục trong ngăn xếp lui, cho phép giữ lại trạng thái trong khi một mục nằm trong ngăn xếp lui
Hệ thống bố cục thích ứng cho phép hiển thị nhiều đích đến cùng một lúc và cho phép chuyển đổi liền mạch giữa các bố cục đó
Cơ chế để nội dung giao tiếp với bố cục mẹ (siêu dữ liệu)
Nhìn chung, bạn triển khai Navigation 3 theo các cách sau:
Xác định nội dung mà người dùng có thể điều hướng đến trong ứng dụng, mỗi nội dung có một khoá duy nhất và thêm một hàm để phân giải khoá đó cho nội dung. Xem phần Giải quyết khoá
cho nội dung.
Tạo ngăn xếp lui mà các khoá được đẩy vào và xoá khi người dùng di chuyển trong ứng dụng. Hãy xem phần Tạo ngăn xếp lui.
Sử dụng NavDisplay để hiển thị ngăn xếp lui của ứng dụng. Bất cứ khi nào ngăn xếp lui thay đổi, ngăn xếp này sẽ cập nhật giao diện người dùng để hiển thị nội dung có liên quan. Xem phần Hiển thị ngăn xếp lui.
Sửa đổi chiến lược cảnh của NavDisplay nếu cần để hỗ trợ bố cục thích ứng và nhiều nền tảng.
Navigation 3 cải tiến API Điều hướng Jetpack ban đầu theo các cách sau:
Cung cấp khả năng tích hợp đơn giản hơn với Compose
Cho phép bạn toàn quyền kiểm soát ngăn xếp lui
Cho phép tạo các bố cục có thể đọc nhiều đích đến từ ngăn xếp lui cùng một lúc, cho phép các bố cục đó thích ứng với các thay đổi về kích thước cửa sổ và các dữ liệu đầu vào khác.
Đọc thêm về các nguyên tắc của Navigation 3 và các lựa chọn thiết kế API trong bài đăng trên blog này.
Mã mẫu
Kho lưu trữ công thức chứa các ví dụ về cách sử dụng các khối xây dựng Navigation 3 để giải quyết các thách thức thường gặp về điều hướng.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Navigation 3\n\n| **Experimental:** Navigation 3 is in alpha. The APIs may change in the future. Please file bugs and feedback using the [issue tracker](https://issuetracker.google.com/issues/new?component=1750212&template=2102223).\n\nNavigation 3 is a new navigation library designed to work with Compose. With\nNavigation 3, you have full control over your back stack, and navigating to and\nfrom destinations is as simple as adding and removing items from a list. It\ncreates a flexible app navigation system by providing:\n\n- Conventions for modeling a back stack, where each entry on the back stack represents content that the user has navigated to\n- A UI that automatically updates with back stack changes (including animations)\n- A scope for items in the back stack, allowing state to be retained while an item is in the back stack\n- An adaptive layout system that allows multiple destinations to be displayed at the same time, and allowing seamless switching between those layouts\n- A mechanism for content to communicate with its parent layout (metadata)\n\nAt a high level, you implement Navigation 3 in the following ways:\n\n1. Define the content that users can navigate to in your app, each with a unique key, and add a function to resolve that key to the content. See [Resolve keys\n to content](/guide/navigation/navigation-3/basics#resolve-keys).\n2. Create a back stack that keys are pushed onto and removed as users navigate your app. See [Create a back stack](/guide/navigation/navigation-3/basics#create-back).\n3. Use a [`NavDisplay`](/reference/kotlin/androidx/navigation3/ui/package-summary#NavDisplay(kotlin.collections.List,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,kotlin.Function1,kotlin.collections.List,androidx.navigation3.ui.SceneStrategy,androidx.compose.animation.SizeTransform,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function1)) to display your app's back stack. Whenever the back stack changes, it updates the UI to display relevant content. See [Display\n the back stack](/guide/navigation/navigation-3/basics#display-back).\n4. Modify `NavDisplay`'s [scene strategies](/guide/navigation/navigation-3/custom-layouts) as needed to support adaptive layouts and different platforms.\n\nYou can see the [full source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:navigation3/) for Navigation 3 on AOSP.\n\nImprovements upon Jetpack Navigation\n------------------------------------\n\nNavigation 3 improves upon the original Jetpack Navigation API in the following\nways:\n\n- Provides a simpler integration with Compose\n- Offers you full control of the back stack\n- Makes it possible to create layouts that can read more than one destination from the back stack at the same time, allowing them to adapt to changes in window size and other inputs.\n\nRead more about Navigation 3's principles and API design choices in [this blog\npost](https://android-developers.googleblog.com/2025/05/announcing-jetpack-navigation-3-for-compose.html).\n\nCode samples\n------------\n\nThe [recipes repository](https://github.com/android/nav3-recipes) contains examples of how to use the\nNavigation 3 building blocks to solve common navigation challenges."]]