Mykola
03/31/2022, 1:36 PMDetailsScreen
with MainScreen
background (Color.Red), but instead I see white background. 😕Mikael Ohlson
03/31/2022, 6:11 PMMykola
03/31/2022, 7:10 PMMikael Ohlson
03/31/2022, 7:35 PMMykola
04/01/2022, 2:28 PMMikael Ohlson
04/01/2022, 3:31 PMNavHost(
navController = navController,
startDestination = ...,
modifier = Modifier.background(color= Color.Green.copy(alpha = 0.2f))
) {
Mykola
04/04/2022, 12:39 PMMikael Ohlson
04/04/2022, 12:44 PMMykola
04/04/2022, 3:17 PMMikael Ohlson
04/04/2022, 3:44 PMif (someBoolean) {
ScreenA()
} else {
ScreenB()
}
If you want ScreenB on top of ScreenA, then you have to do something similar to:
```if (someBoolean) {
ScreenA()
} else {
ScreenA()
ScreenB()
}```and make sure they align as you want them to.
Mykola
04/04/2022, 5:41 PMMikael Ohlson
04/04/2022, 7:13 PM@Composable
fun DetailsScreen() {
Column(
modifier = Modifier.background(Color.Green)
) {
Text(text = "Details Screen")
}
}
is being rendered as a small green screen text atop a white background. Which is quite understandable, since both the nav host and the column will shrink wrap the text view. What you are seeing is the activity window and its default background.
If you set your activity’s theme to be translucent, your whole nav host and everything in it will be transparent.
<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
<item name="android:background">#33000000</item> <!-- Or any transparency or color you need -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>
Here is me using Navigation to navigate between two screens. The only change from my “normal” setup is that I’ve changed the activity theme in AndroidManifest to that given above.Mykola
04/04/2022, 9:03 PMMikael Ohlson
04/05/2022, 10:03 AMComposable
fun AppNav(navController: NavHostController) {
NavHost(
navController = navController,
startDestination = "main"
) {
composable("main") {
MainScreen { navController.navigate("details") }
}
composable("details") {
MainScreen { }
DetailsScreen()
}
}
}
and if you want it to use fading and stuff like that, you probably have to add a modifier / surface for that. Of course you can still use the compose navigation component to navigate to a separate fragment / activity on top of your current content.
Making it possible to pass modifiers to your MainScreen may be useful, since you may want to pass a blur modifier or similar to it when drawing it behind the Details Screen.Mykola
04/05/2022, 1:53 PMcomposable("details") {
MainScreen { }
DetailsScreen()
}
My MainScreen is extremely complicated and I don’t want to recompose it again just to be able to place DetailsScreen() on top of itMikael Ohlson
04/05/2022, 3:01 PMMykola
04/05/2022, 3:33 PMMikael Ohlson
04/05/2022, 3:42 PM