依赖
implementation 'androidx.compose.ui:ui:1.4.3'
implementation 'androidx.compose.ui:ui-tooling:1.4.3'
implementation 'androidx.compose.material:material:1.4.3'
implementation 'androidx.compose.material:material-icons-extended:1.4.3'
implementation 'androidx.compose.runtime:runtime-livedata:1.4.3'
implementation 'androidx.compose.animation:animation:1.4.3'
implementation 'androidx.activity:activity-compose:1.7.0'
implementation 'com.google.accompanist:accompanist-systemuicontroller:0.30.1'
Activity
下面展示一些 内联代码片
。
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// WindowCompat.setDecorFitsSystemWindows(window, false)
setContent{
TransparentSystemBars()
}
}
}
@Composable
fun TransparentSystemBars() {
val systemUiController = rememberSystemUiController()
val useDarkIcons = !isSystemInDarkTheme()
SideEffect {
systemUiController.setSystemBarsColor(
color = Color.Transparent,
darkIcons = useDarkIcons,
isNavigationBarContrastEnforced = false
)
systemUiController.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
systemUiController.isStatusBarVisible = false
systemUiController.isSystemBarsVisible = false
systemUiController.isNavigationBarVisible = false //navigation bar
}
}
其中 A SideEffect runs after every recomposition