我正在使用 Jetpack Compose 开发一个应用程序,在 Theme.kt 中我已导入并覆盖了primaryColor,如图所示
private val LightColorScheme = lightColorScheme(
primary = Primary
)
下面我不支持动态颜色或浅色/深色模式,因为我只想要一组颜色。
@Composable
fun MarkettrackerTheme(
content: @Composable () -> Unit
) {
MaterialTheme(
colorScheme = LightColorScheme,
typography = MarketTrackerTypography,
content = content
)
}
然后我的整个应用程序都被 MainActivity.kt 中的主题包围,然后我用灰色容器颜色、导航栏和其他可组合项/屏幕包围包含支架的 MainScreen.kt。当我进入应用程序时,它会显示加载文本,并且在几分之一秒的时间里它是黑色的,然后变成白色。另外,当一些文本失去构图时,当我回到它们时,它们会从黑色变成白色......
setContent {
MarkettrackerTheme {
MainScreen(
onProductClick = {
NavigateAux.navigateTo<ProductDetailsActivity>(this)
}
)
}
}
@Composable
fun MainScreen() {
val navController = rememberNavController()
var selectedIndex by rememberSaveable { mutableIntStateOf(0) }
Scaffold(
containerColor = Grey,
bottomBar = {
// NavBar...
}
) {
NavHost(
navController = navController,
startDestination = Destination.HOME.route,
enterTransition = { fadeIn(tween(400)) },
exitTransition = { fadeOut(tween(200)) },
modifier = Modifier.padding(it)
) {
composable("home") {
PullToRefreshLazyColumn(
isRefreshing = isRefreshing,
onRefresh = {
scope.launch {
// logic to refresh products...
}
}
) {
if(isLoading) LoadingIcon()
else LazyColumn(...)
}
}
每次变化的文字就是LoadingIcon那一个:
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(id = R.drawable.mt_logo),
contentDescription = "LoadingIcon",
modifier = Modifier.rotate(rotation)
)
text?.let {
Text(text = it) // this changes from black to white in almost 1s
}
}
预览很好,我的 Android 版本是 10。我的朋友说他的手机没有发生同样的情况,他的 Android 版本是 11。
我尝试在硬编码的文本上设置颜色,使用样式,用主题围绕文本,但没有任何效果,它显示黑色一段时间,然后显示白色。
已修复
原来小米手机在应用程序中强制使用深色主题,所以我将以下行添加到themes.xml:
<item name="android:forceDarkAllowed">false</item>