【发布时间】:2023-01-03 18:16:00
【问题描述】:
我想将 TopAppBar 添加到我的 Compose 应用程序中,因此我执行了以下操作:
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AlternoTubeTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
stringResource(id = R.string.app_name),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
},
)
},
content = { innerPadding ->
MyAppTheme(modifier = Modifier.padding(innerPadding))
}
)
}
}
}
}
问题是,当我运行应用程序时,TopAppBar 没有颜色:
而在预览图像上,应用栏确实有颜色:
接下来我可以尝试什么来获得正确的颜色?
【问题讨论】:
标签: android kotlin android-jetpack-compose jetpack android-jetpack-compose-material3