xxxxxxxxxx
@Composable
private fun OrientationSample() {
Column(modifier = Modifier.fillMaxSize()) {
val activity = (LocalContext.current as Activity)
Button(onClick = {
val orientation = activity.requestedOrientation
val newOrientation = if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
} else {
// This is where you lock to your preferred one
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
activity.requestedOrientation = newOrientation
}) {
Text("Toggle Orientation")
}
}
}