androidx.compose.material3.windowsizeclass
Classes
WindowHeightSizeClass |
Height-based window size class. |
Cmn
|
WindowSizeClass |
Window size classes are a set of opinionated viewport breakpoints to design, develop, and test responsive application layouts against. |
Cmn
|
WindowWidthSizeClass |
Width-based window size class. |
Cmn
|
Annotations
Top-level functions summary
WindowSizeClass |
Calculates the window's |
android
|
Top-level functions
calculateWindowSizeClass
@ExperimentalMaterial3WindowSizeClassApi
@Composable
fun calculateWindowSizeClass(activity: Activity): WindowSizeClass
Calculates the window's WindowSizeClass
for the provided activity
.
A new WindowSizeClass
will be returned whenever a configuration change causes the width or height of the window to cross a breakpoint, such as when the device is rotated or the window is resized.
import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass class MyActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { // Calculate the window size class for the activity's current window. If the window // size changes, for example when the device is rotated, the value returned by // calculateSizeClass will also change. val windowSizeClass = calculateWindowSizeClass(this) // Perform logic on the window size class to decide whether to use a nav rail. val useNavRail = windowSizeClass.widthSizeClass > WindowWidthSizeClass.Compact // MyScreen knows nothing about window size classes, and performs logic based on a // Boolean flag. MyScreen(useNavRail = useNavRail) } } }