相关疑难解决方法(0)

文本可组合维度资源不能用作 fontSize 参数

当我插入 fontSize =DimensionResource(id = R.dimen.textLabelTextSize) 时,其中 dimens 或 54sp 或 60sp 取决于设备,我在 Text() 上收到错误“无法使用提供的参数调用以下函数。 ” 但是当我输入像 54sp 这样的硬编码值时就很好了。奇怪的是填充修饰符维度资源(以 dp 为单位)工作正常。

       Text(
                text = textLabelItem.textLabel,
                modifier = Modifier
                    .padding(
                        start = dimensionResource(id = R.dimen.textLabelPaddingVertical),
                        top = dimensionResource(id = R.dimen.textLabelPaddingHorizontalTop),
                        end = dimensionResource(id = R.dimen.textLabelPaddingVertical),
                        bottom = dimensionResource(id = R.dimen.textLabelPaddingHorizontalBottom)
                    )
                    .background(colorResource(id = R.color.textLabelBg))
                    .border(
                        width = 2.dp,
                        color = colorResource(id = R.color.textLabelBorder),
                        shape = RoundedCornerShape(8.dp)
                    ),
                color = colorResource(id = android.R.color.background_dark),
                fontSize = dimensionResource(id = R.dimen.textLabelTextSize),
                fontWeight = FontWeight.Bold
            )
Run Code Online (Sandbox Code Playgroud)

android kotlin android-resources android-jetpack-compose

22
推荐指数
3
解决办法
6026
查看次数