kotlin Jetpack Compose中的应用程序/脚手架白色背景更改问题

ne5o7dgx  于 2023-06-24  发布在  Kotlin
关注(0)|答案(4)|浏览(232)

有没有人能告诉我如何改变这个白色背景的应用程序?在Surface上设置颜色或背景色没有任何影响。我已经为Scaffold中的内容设置了青色背景,只是为了调试这个问题。

class MainActivity : ComponentActivity() {
        ...
        setContent {
            ChakkarTheme {
                Surface(
                    color = Color.Red, modifier = Modifier
                        .fillMaxSize()
                        .background(Color.DarkGray)
                ) {
                    ChakkarApp()
                }
            ...
@Composable
fun ChakkarApp() {
    Scaffold(
        topBar = { TopAppBar(title = { Text(appTitle) }, navigationIcon = navigationIcon) },
        floatingActionButtonPosition = FabPosition.End,
        floatingActionButton = {
            if (showFab) {
                FloatingActionButton(onClick = { /*TODO*/ }) {
                    Icon(imageVector = Icons.Filled.Add, contentDescription = null)
                }
            }
        },
        bottomBar = {
            BottomNavigation() {
                val navBackStackEntry by navController.currentBackStackEntryAsState()
                val currentDestination = navBackStackEntry?.destination
                bottomNavItems.forEach { screen ->
                    BottomNavigationItem(
                        icon = { Icon(imageVector = screen.icon, contentDescription = null) },
                        label = { Text(stringResource(id = screen.resourceId)) },
                        selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
                        onClick = {
                            navController.navigate(screen.route) {
                                popUpTo(navController.graph.findStartDestination().id) {
                                    saveState = true
                                }
                                launchSingleTop = true
                                restoreState = true
                            }
                        }
                    )
                }
            }
        }
    ) { paddingValues ->

        Column(
            modifier = Modifier
                .verticalScroll(rememberScrollState())
                .background(Color.Cyan)
                .padding(paddingValues)
                .padding(16.dp)
        ) {
            NavHost(
                navController = navController,
                startDestination = Screen.Running.route
            ) {
...

谢谢你的帮助!

yhived7q

yhived7q1#

Scaffold的默认背景色为MaterialTheme.colors.background
可以指定自定义值:

Scaffold(
    ...
    backgroundColor = Color.DarkGray,
)
0aydgbwb

0aydgbwb2#

你可以尝试在你的Scaffold中添加modifier = Modifier.fillMaxSize().background(color = Color.Black)backgroundColor = Color.Black吗?
+**编辑:**add Modifier不工作。尝试在Scaffold中添加backgroundColor
像这样:

MaterialTheme {
    Scaffold(
        content = {
            Box(modifier = Modifier.size(500.dp).background(color = Color.Cyan))
        },
        backgroundColor = Color.Black
    )
}

7rtdyuoh

7rtdyuoh3#

从下面的代码片段设置完整的背景颜色Modifier.fillMaxSize()它给出了一个完整的高度和宽度。Modifier.background(Color.Grey)通过使用background可以设置背景颜色。

Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Grey)
) {
    Column(
        modifier = Modifier
            .verticalScroll(
                state = rememberScrollState()
            )
    ) {
        Text(
            text = profileViewModel.loginUserDetail.lastName,
            fontSize = 18.sp,
            color = Color.White,
            fontFamily = myFontFamily,
            fontWeight = FontWeight.SemiBold,
            modifier = Modifier.padding(5.dp, 5.dp, 5.dp, 5.dp),
        )
    }
}
0dxa2lsx

0dxa2lsx4#

你可以根据这个代码修改它,这是新的。

Scaffold(
  modifier = Modifier.background(Color.Red),
  content = {
    // Your content here
  }
)

这是旧的。

Scaffold(

    backgroundColor = Color.DarkGray,
)

相关问题