在我的应用程序中,我有一些风格继承了另一种风格,比如:
styles.xml
<style name="RegularM">
<item name="android:textSize">18sp</item>
<item name="android:fontFamily">@font/regular</item>
</style>
<style name="ListRow" parent="RegularM">
<item name="android:textColor">@color/black</item>
</style>这使得ListRow条目成为带有18 and的黑色文本,并使用常规字体。
所以,现在我把这个转换成作品。
Fonts.kt
val Regular = FontFamily(
Font(R.font.regular),
)
val RegularM = TextStyle(
fontFamily = Regular,
fontSize = 18.sp
)到现在为止还好。
现在我想创建ListRow TextStyle:
val ListRow = TextStyle(
color = Black,
? inherit from RegularM
)但我不能继承RegularM的遗产。我必须为ListRow TextStyle重新键入每个属性。但这似乎是不对的。
我是如何从RegularM继承的,还是对此使用TextStyle是错误的?
发布于 2021-08-18 10:18:22
TextStyle不是一个数据类,但是仍然实现了copy(...)方法,您完全可以使用它来解决这个问题:
var ListRow = RegularM.copy(color = Black)发布于 2021-08-18 11:13:51
使用TestStyle,您可以使用@Philip的copy方法as suggested,但也可以使用方法。
示例:
Text(text = "This is my text",
style = (
RegularM.merge(TextStyle(color = Black))
)
)https://stackoverflow.com/questions/68830471
复制相似问题