简体   繁体   English

为什么我的修改器在 Jetpack Compose 中不起作用

[英]Why won't my modifiers work in jetpack compose

I am learning jetpack compose and I can't seem to understand why the the first value after my modifier will stay as an unnamed reference even after I import it.我正在学习 jetpack compose,但我似乎无法理解为什么我的修饰符后的第一个值即使在我导入后仍将作为未命名的引用保留下来。

The ".width" is what won't work albeit if it were to be deleted the height wouldn't work. “.width”是行不通的,即使它被删除,高度也行不通。

Note: All imports concerning width etc are there注意:所有关于宽度等的进口都在那里

Text(
        text = "Johanthon",
        textAlign = TextAlign.Start,
        fontSize = 16.sp,
        textDecoration = TextDecoration.None,
        letterSpacing = 0.sp,
        overflow = TextOverflow.Ellipsis,
        modifier = Modifier
            .width(100.dp)
            .height(21.dp)
            .alpha(1f),
        color = Color(red = 0f, green = 0f, blue = 0f, alpha = 1f),
        fontWeight = FontWeight.Bold,
        fontStyle = FontStyle.Normal,
    )

I had the same issue and just found out it was because I'd imported the wrong Modifier.我遇到了同样的问题,只是发现这是因为我导入了错误的修改器。 I'd imported some java.lang thing.我导入了一些 java.lang 的东西。 Make sure you've got import androidx.compose.ui.Modifier .确保你有import androidx.compose.ui.Modifier

Hope your solution is something as simple as that!希望您的解决方案就是这么简单!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM