kotlin 在Scaffold- Compose - Transparent底部栏中将pacer添加到导航主机

ilmyapht  于 2023-08-06  发布在  Kotlin
关注(0)|答案(1)|浏览(101)

我试图应用我自己的底部栏,它有一个透明的背景,但它需要添加一个Spacer(不填充)与底部栏的高度(56.dp)在所有屏幕的底部。然而,当我在支架中添加间隔物时,似乎间隔物不适用。

@Composable
fun MainScreen(navHostController: NavHostController) {
    Scaffold(
        bottomBar = { BottomBar(navHostController = navHostController) }
    ) { innerPadding ->
        Box(
            modifier = Modifier
                .fillMaxSize()
        ) {
            SetupNavGraph(navController = navHostController)
            Spacer(modifier = Modifier.height(56.dp).align(Alignment.BottomCenter))
        }

    }

}

字符串

7gyucuyw

7gyucuyw1#

您正在使用一个Box,它覆盖了它们的子节点。NavHost将与垫片重叠,而不是位于垫片上方。如果您希望NavHost位于垫片上方,请使用带权重的Column,

@Composable
fun MainScreen(navHostController: NavHostController) {
    Scaffold(
        bottomBar = { BottomBar(navHostController = navHostController) }
    ) { innerPadding ->
        Column(
            modifier = Modifier.fillMaxSize()
        ) {
            SetupNavGraph(navController = navHostController, modifier = Modifier.weight(1f))
            Spacer(modifier = Modifier.height(56.dp)
        }
    }
}

字符串
但是,您应该使用脚手架提供的填充,它占了底部栏:

@Composable
fun MainScreen(navHostController: NavHostController) {
    Scaffold(
        bottomBar = { BottomBar(navHostController = navHostController) }
    ) { innerPadding ->
        SetupNavGraph(navController = navHostController, modifier = Modifier.padding(innerPadding))
    }
}

相关问题