无法在材料设计中使用lotcontentalpha更改文本重点3
目前,我将我的一个应用程序之一迁移到材料设计3,该材料设计3完全使用JetPack Copose迁移。
在使用材料设计2时,我能够使用以下代码更改文本的重点。
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
Text(
text = "Hello, world",
style = MaterialTheme.typography.h6,
fontWeight = FontWeight.SemiBold,
)
}
但是,相同的代码对于材料设计3不起作用,并且文本具有默认的重点。另外,我找不到材料设计的任何地方的相关功能3。我想知道是否有任何官方方法可以达到相同的效果。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
材料thepograph.h6
来自材料2,这意味着您也使用text
也可以从材料2中复合。材料3
H6
的类似物IS材料theme.typography.headlinesmall
。确保您可以正确导入
text
和材料
- 应从androidx.compose.material3
软件包中导入这些。 Also make sure you provide a correctly imported theme, eg错误的进口是迁移到M3时最常见的错误,因此请耐心等待。
另请注意,
LocalContentalPha
在M3中不存在,提供M2版本对M3视图没有影响。您可以比较文本
composable在M2 and in我不确定是否会在以后添加(毕竟是Alpha),或者在M3中以其他方式处理,这是一个解决方法(这不是一个完美的方法):
PS
localContentColor
需求也要从M3进口MaterialTheme.typography.h6
is from Material 2, which means you're usingText
composable from Material 2 too.Material 3 analog of
h6
isMaterialTheme.typography.headlineSmall
.Make sure you have correct imports of both
Text
andMaterialTheme
- these should be imported fromandroidx.compose.material3
package. Also make sure you provide a correctly imported theme, e.g. here.Wrong imports is the most common mistake when migrating to M3, so be patient with it.
Also note that
LocalContentAlpha
doesn't exists in M3, providing M2 version will have no effect on M3 views. You can compare howText
composable determines its color in M2 and in M3.I'm not sure wether it's gonna be added later (it's alpha after all), or it's handled in some other way in M3, here's a workaround(which is not perfect for sure):
p.s.
LocalContentColor
needs to be imported from M3 too“ 强调和内容alpha =“ https://developer.android.com/jetpack/compose/compose/designsystems/material2-material3#m3_16” rel =“ noreferrer”>从材料2迁移到材料3到compose 详细信息的详细信息。
材料2:
材料3:
The "Emphasis and content alpha" section in the Migrate from Material 2 to Material 3 in Compose details the API changes.
Material2:
Material3: