尝试在android studio中更改为dark主题时出错,尝试更改主题(使用代码)时状态未发生更改,文本和背景均未更改
这是密码:
@Composable
fun MyCompnent(){
Row(modifier = Modifier
.background(MaterialTheme.colors.background)
.padding(8.dp)) {
MyImageView()
MyTexts()
}
}
@Composable
fun MyTexts(){
Column(modifier = Modifier.padding(start = 5.dp)) {
MyText(
"HELLO",
MaterialTheme.colors.primary,
MaterialTheme.typography.subtitle1
)
Spacer(modifier = Modifier.height(9.dp))
MyText(
"WORLD",
MaterialTheme.colors.onBackground,
MaterialTheme.typography.subtitle2
)
}
}
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
fun PreviewComposable(){
MyCompnent()
}
package com.example.tomasardiles.ui.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
private val DarkColorPalette = darkColors(
primary = Purple200,
primaryVariant = Purple700,
secondary = Teal200,
onBackground = white
)
private val LightColorPalette = lightColors(
primary = Purple500,
primaryVariant = Purple700,
secondary = Teal200,
onBackground = black
)
package com.example.tomasardiles.ui.theme
import androidx.compose.ui.graphics.Color
val Purple200 = Color(0xFFBB86FC)
val Purple500 = Color(0xFF6200EE)
val Purple700 = Color(0xFF3700B3)
val Teal200 = Color(0xFF03DAC5)
val white = Color.White
val black = Color.Black
我按照一门课程编写了代码,我所期望的是背景会变成黑色,单词"WORLD"会变成白色
2条答案
按热度按时间vnzz0bqm1#
**更新更新
一旦它进入黑暗模式,一旦用户界面模式似乎工作?
**更新
我不得不在预览中手动将其翻转到黑暗模式。我没有发现uimode可以工作:
看看如何定义你的主题。
njthzxwz2#
尝试使用
AppTheme
可组合函数更新Theme
文件,如下所示:然后在
MainActivity
文件中添加以下AppTheme
: