adaptive
Skill này làm gì
Skill này hướng dẫn làm cho ứng dụng Compose Android phản ứng với nhiều kích thước màn hình và thiết bị khác nhau. Nó bao quát điều hướng, bố cục nhiều khung, danh sách và việc giữ trạng thái khi xoay màn hình. Nó dành cho lập trình viên Android muốn ứng dụng hoạt động vượt ra ngoài điện thoại.
Khi nào nên dùng
- ✓Khi bạn muốn ứng dụng Android hoạt động tốt trên máy tính bảng và màn hình gập cũng như điện thoại.
- ✓Khi bạn cần bố cục nhiều khung hoặc thanh điều hướng thay đổi theo kích thước màn hình.
- ✓Khi bạn muốn các màn hình và việc phát media của ứng dụng giữ được trạng thái qua các thay đổi cấu hình.
Liên kết skill
https://github.com/android/skills/blob/main/jetpack-compose/adaptive/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm cho ứng dụng Compose Android của tôi thích ứng với máy tính bảng, màn hình gập và cửa sổ máy tính.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill bắt đầu bằng việc đảm bảo đã có các kiểm thử ảnh chụp màn hình cho các kích thước màn hình chính, rồi làm cho điều hướng, bố cục và danh sách thích ứng từng bước. Nó cũng xử lý việc giữ trạng thái và hỗ trợ màn hình gập.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Prerequisites
The app must:
- Use Compose for all screens. If it's still using Fragments or Views, suggest using the XML to Compose skill to migrate those screens.
- Use Jetpack Navigation 3. If it doesn't, suggest the Navigation 3 skill to migrate the app.
Workflow to make an app adaptive
To make an app adaptive, follow these steps or a subset of them adapting to the task.
- Step 1: Verify current UI
- Step 2: Make the navigation bar adaptive
- Step 3: Add multi-pane layouts
- Step 4: Make vertical lists adaptive by changing the number of columns
- Step 5: Hide app bars when scrolling
- Step 6: Preserve UI state across configuration changes
- Step 7: Add desktop experiences
- Step 8: Support foldable devices
Step 1. Verify current UI
Ensure that screenshot tests exist to verify the current UI on different form factors. If they don't exist, add the Compose Preview Screenshot Testing tool. Use the following annotation to create previews for all the major form factors. For example:
@Preview(name = "Phone", device = Devices.PHONE, showBackground = true)
@Preview(name = "Foldable", device = Devices.FOLDABLE, showBackground = true)
@Preview(name = "Tablet", device = Devices.TABLET, showBackground = true)
@Preview(name = "Desktop", device = Devices.DESKTOP, showBackground = true)
annotation class FormFactorPreviews
@PreviewTest
@FormFactorPreviews
@Composable
fun FeedScreenPreview() {
SnippetsTheme {
Box {
Text("My Screen")
}
}
}
<br />
Step 2. Make the navigation bar adaptive
Bottom navigation bars are optimized for touch input when the user is holding a phone in portrait mode. On larger screen hand-held devices, like tablets and unfolded foldables, the navigation area must be accessible from the edge of the screen (navigation rail).
If you need to provide more screen space for the content, hide the navigation area. Examples of this include:
- Hiding the navigation bar when the user scrolls down and showing it again when the user scrolls up. The assumption is that when the user is scrolling down, they are consuming content but when scrolling up they are trying to navigate away from that content.
- Hiding the navigation area when its content is distracting. For example, in camera previews or when displaying a full-screen photo.
When the detail screen is displayed full-screen on mobile, full-screen mode must be deactivated on larger screens.
Steps to migrate:
- Locate the existing navigation bar.
- Convert each item to a
NavigationSuiteItem. - Identify whether the navigation bar's visibility changes. For example, if it is wrapped with an
AnimatedContentorAnimatedVisibilitycomposable. If so, follow the guidance in the "Control navigation area visibility". - Replace the container that held the navigation bar (often a
Scaffold) withNavigationSuiteScaffoldfrom the Material 3 adaptive layouts library. - Supply the navigation items using the
navigationItemsparameter ofNavigationSuiteScaffold.
Step 2.1. Control navigation area visibility
If the navigation bar's visibility changes - it is hidden under certain
scenarios or on certain screens - this behavior must be maintained with the
adaptive navigation area. This is done using NavigationSuiteScaffold's state
parameter.
Steps to migrate:
- Identify the scenarios under which the navigation bar is hidden. This is usually done with a boolean variable for the visibility. Use
isNavBarVisibleorshouldShowNavBaras the variable name. - Create an instance of
NavigationSuiteScaffoldStateusingrememberNavigationSuiteScaffoldState()and pass it toNavigationSuiteScaffold. - When the navigation area visibility changes, use a
LaunchedEffectto callshoworhideon theNavigationSuiteScaffoldState.
For example:
// Pass this variable to any composable that needs to control the navigation area visibility
var isNavBarVisible by remember { mutableStateOf(true) }
val scaffoldVisibilityState = rememberNavigationSuiteScaffoldState()
NavigationSuiteScaffold(
navigationSuiteItems = navItems,
state = scaffoldVisibilityState
) {
// Main content
}
LaunchedEffect(isNavBarVisible){
if (isNavBarVisible) {
scaffoldVisibilityState.show()
} else {
scaffoldVisibilityState.hide()
}
}
<br />
Step 3. Add multi-pane layouts using Navigation 3
Câu hỏi thường gặp
Ứng dụng phải đã dùng gì?
Ứng dụng phải dùng Jetpack Compose cho các màn hình và Jetpack Navigation 3. Nếu chưa, skill gợi ý chuyển đổi trước.
Nó có thêm kiểm thử không?
Có. Nó đảm bảo có các kiểm thử ảnh chụp màn hình để kiểm tra giao diện hiện tại trên các dạng thiết bị khác nhau.
Nó có hỗ trợ chuột và bàn phím không?
Có. Skill bao quát các thiết bị trỏ như chuột và nhập văn bản bằng bàn phím.
Chi tiết
Mô tả gốc của tác giả
Instructions to make or update an app's UI so that it adapts to different Android devices including phones, tablets, foldables, laptops, desktop, TV, Auto, and XR. It includes how to handle different window sizes, pointing devices (such as mouse) and text entry devices (such as keyboard) using the Compose MediaQuery API, and how to preserve UI, navigation, scroll, and media playback state across configuration changes (such as folding/unfolding a foldable, rotating a device, or resizing a window). It also covers multi-pane layouts using Navigation3 Scenes, adaptive UI components (such as button
repo: android/skills
Độ phổ biến
- Sao GitHub
- 10k
- Vị trí xếp hạng
- #11918
- Giấy phép
- Apache-2.0
- Cập nhật
- 29/10/2026
Bình luận
- …
Thêm skill từ kho mã này
agp-9-upgrade
10kGiúp agent của bạn nâng cấp ứng dụng Android lên Android Gradle Plugin 9 và xử lý các thay đổi gây lỗi. Không dành cho dự án đa nền tảng.
camerax
10kGiúp agent của bạn xây dựng các tính năng camera Android bằng CameraX, gồm quay video, điều khiển phần cứng, ML Kit và hiệu ứng Media3.
android-for-cars-parked-apps
10kĐiều chỉnh một ứng dụng video, trò chơi hoặc trình duyệt Android để chạy như ứng dụng khi xe đỗ trên Android Auto và Android Automotive.
appfunctions
10kTìm các luồng công việc chính trong ứng dụng Android và công khai chúng dưới dạng AppFunctions để agent AI và lệnh giọng nói có thể chạy.
Skill tương tự
android-clean-architecture
280kGiúp agent của bạn tổ chức dự án Android hiệu quả, cấu trúc code để việc bảo trì và phát triển tính năng mới dễ dàng hơn.
compose-multiplatform-patterns
280kGiúp agent của bạn dùng các mẫu Compose Multiplatform và Jetpack Compose trong dự án KMP, gồm trạng thái, điều hướng, giao diện và hiệu năng.
dart-flutter-patterns
280kGiúp agent của bạn viết code cho ứng dụng Dart và Flutter. Agent dùng các mẫu hiện đại để tạo ứng dụng vững chắc và dễ quản lý.