@ComposablefunMyApp(windowSizeClass:WindowSizeClass=currentWindowAdaptiveInfo().windowSizeClass){// Decide whether to show the top app bar based on window size class.valshowTopAppBar=windowSizeClass.isHeightAtLeastBreakpoint(WindowSizeClass.HEIGHT_DP_MEDIUM_LOWER_BOUND)// MyScreen logic is based on the showTopAppBar boolean flag.MyScreen(showTopAppBar=showTopAppBar,/* ... */)}
[null,null,["最后更新时间 (UTC):2025-08-22。"],[],[],null,["# Use window size classes\n\nWindow size classes are a set of opinionated viewport breakpoints that help you\ndesign, develop, and test responsive/adaptive layouts. The breakpoints balance\nlayout simplicity with the flexibility of optimizing your app for unique cases.\n\nWindow size classes categorize the display area available to your app as\n*compact* , *medium* , *expanded* , *large* , or *extra large*. Available width and\nheight are classified separately, so at any point in time, your app has two\nwindow size\nclasses---one for width, one for height. Available width is usually more\nimportant than available height due to the ubiquity of vertical scrolling, so\nthe width window size class is likely more relevant to your app's UI.\n**Figure 1.** Representations of width-based window size classes. **Figure 2.** Representations of height-based window size classes.\n\nAs visualized in the figures, the breakpoints allow you to continue thinking\nabout layouts in terms of devices and configurations. Each size class breakpoint\nrepresents a majority case for typical device scenarios, which can be a helpful\nframe of reference as you think about the design of your breakpoint-based\nlayouts.\n\n| Size class | Breakpoint | Device representation |\n|-------------------|--------------------------|-------------------------------------------------------------------------------------------------------------|\n| Compact width | width \\\u003c 600dp | 99.96% of phones in portrait |\n| Medium width | 600dp ≤ width \\\u003c 840dp | 93.73% of tablets in portrait, most large unfolded inner displays in portrait |\n| Expanded width | 840dp ≤ width \\\u003c 1200dp | 97.22% of tablets in landscape, most large unfolded inner displays in landscape are at least expanded width |\n| Large width | 1200dp ≤ width \\\u003c 1600dp | Large tablet displays |\n| Extra-large width | width ≥ 1600dp | Desktop displays |\n| Compact height | height \\\u003c 480dp | 99.78% of phones in landscape |\n| Medium height | 480dp ≤ height \\\u003c 900dp | 96.56% of tablets in landscape, 97.59% of phones in portrait |\n| Expanded height | height ≥ 900dp | 94.25% of tablets in portrait |\n\n| **Note:** Most apps can build an adaptive UI by considering only the width window size class. However, also consider the height window size class for scenarios such as phones or open flippables in landscape orientation; the window width is typically medium, but window height is compact, in which case two pane layouts are not practical.\n\nAlthough visualizing size classes as physical devices can be useful, window size\nclasses are explicitly not determined by the size of the device screen. Window\nsize classes are not intended for *isTablet*‑type logic. Rather, window\nsize classes are determined by the window size available to your application\nregardless of the type of device the app is running on, which has two important\nimplications:\n\n- **Physical devices do not guarantee a specific window size class.** The\n screen space available to your app can differ from the screen size of the\n device for many reasons. On mobile devices, split‑screen mode can\n partition the screen between two applications. On ChromeOS, Android apps can\n be presented in desktop‑type windows that are arbitrarily resizable.\n Foldables can have two different‑sized screens individually accessed\n by folding or unfolding the device.\n\n- **The window size class can change throughout the lifetime of your app.**\n While your app is running, device orientation changes, multitasking, and\n folding/unfolding can change the amount of screen space available. As a\n result, the window size class is dynamic, and your app's UI should adapt\n accordingly.\n\nWindow size classes map to the compact, medium, and expanded breakpoints in the\n[Material Design layout\nguidance](https://m3.material.io/foundations/layout/applying-layout/window-size-classes).\nUse window size classes to make high‑level application layout decisions,\nsuch as deciding whether to use a specific canonical layout to take advantage of\nadditional screen space.\n\nCompute the current [`WindowSizeClass`](/reference/androidx/window/core/layout/WindowSizeClass) using the\n[`currentWindowAdaptiveInfo()`](/reference/kotlin/androidx/compose/material3/adaptive/package-summary#currentWindowAdaptiveInfo()) top‑level function of the\n[`androidx.compose.material3.adaptive`](/reference/kotlin/androidx/compose/material3/adaptive/package-summary) library. The function returns an\ninstance of [`WindowAdaptiveInfo`](/reference/kotlin/androidx/compose/material3/adaptive/WindowAdaptiveInfo), which contains [`windowSizeClass`](/reference/kotlin/androidx/compose/material3/adaptive/WindowAdaptiveInfo#windowSizeClass()). The\nfollowing example shows how to calculate the window size class and receive\nupdates whenever the window size class changes:\n\n\n```kotlin\nval windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass \nhttps://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/layouts/AdaptiveLayoutSnippets.kt#L85-L85\n```\n\n\u003cbr /\u003e\n\nManage layouts with window size classes\n---------------------------------------\n\nWindow size classes enable you to change your app layout as the display space\navailable to your app changes, for example, when a device folds or unfolds, the\ndevice orientation changes, or the app window is resized in multi‑window\nmode.\n\nLocalize the logic for handling display size changes by passing window size\nclasses down as state to nested composables just like any other app state:\n\n\n```kotlin\n@Composable\nfun MyApp(\n windowSizeClass: WindowSizeClass = currentWindowAdaptiveInfo().windowSizeClass\n) {\n // Decide whether to show the top app bar based on window size class.\n val showTopAppBar = windowSizeClass.isHeightAtLeastBreakpoint(WindowSizeClass.HEIGHT_DP_MEDIUM_LOWER_BOUND)\n\n // MyScreen logic is based on the showTopAppBar boolean flag.\n MyScreen(\n showTopAppBar = showTopAppBar,\n /* ... */\n )\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/layouts/AdaptiveLayoutSnippets.kt#L49-L61\n```\n\n\u003cbr /\u003e\n\nTest window size classes\n------------------------\n\nAs you make layout changes, test the layout behavior across all window sizes,\nespecially at the compact, medium, and expanded breakpoint widths.\n\nIf you have an existing layout for compact screens, first optimize your layout\nfor the expanded width size class, since this size class provides the most space\nfor additional content and UI changes. Then decide what layout makes sense for\nthe medium width size class; consider adding a specialized layout.\n\nNext steps\n----------\n\nTo learn more about how to use window size classes to create responsive/adaptive\nlayouts, see the following:\n\n- For Compose-based layouts: [Support different display sizes](/develop/ui/compose/layouts/adaptive/support-different-display-sizes)\n\n- For view-based layouts: [Responsive/adaptive design with views](/develop/ui/views/layout/responsive-adaptive-design-with-views)\n\nTo learn more about what makes an app great on all devices and screen sizes,\nsee:\n\n- [Migrate your UI to responsive layouts](/guide/topics/large-screens/migrate-to-responsive-layouts)\n- [Large screen app quality](/docs/quality-guidelines/large-screen-app-quality)"]]