Jetpack 撰写“文本”功能已弃用 (1.0.0-alpha09)

时间:2020-12-31 20:01:45

标签: android text android-jetpack-compose

(配置:compose_version = '1.0.0-alpha09' kotlin_version = "1.4.21")

不推荐使用 Jetpack Composable 函数“Text”

Text( // <===== Strikethrough in Android Studio
    text = "Anna"
)

但是我不知道如何替换它。文档说要替换为...文本

@Deprecated(
    message = "Use androidx.compose.material.Text for a high level Text component that " +
        "consumes theming information, or androidx.compose.foundation.text.BasicText for a basic " +
        "unopinionated component that does not have default theming",
    replaceWith = ReplaceWith(
        "Text(text, modifier, color, fontSize, fontStyle, fontWeight, fontFamily, " +
            "letterSpacing, textDecoration, textAlign, lineHeight, overflow, softWrap, maxLines, " +
            "onTextLayout, style)",
        "androidx.compose.material.Text"
    )
)

1 个答案:

答案 0 :(得分:4)

将您的 androidx.compose.foundation.Text 导入更改为

import androidx.compose.material.Text

使用 Text 的未弃用 Material 版本,这是对 Text 在以前的 alpha 中所做的替代品的下降。