如何连接单独声明的修饰符? [英] How to concatenate separately declared modifiers?

查看:28
本文介绍了如何连接单独声明的修饰符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

val modifierA = Modifier.size(100.dp)val modifierB = Modifier.background(Color.Red)

如何创建由 A 和 B 串联而成的 modifierC?

我尝试使用 .apply.also,但无济于事.

解决方案

您可以使用

val modifierA = Modifier.size(100.dp)
val modifierB = Modifier.background(Color.Red)

How do you create a modifierC that is the concatenation of A and B?

I tried using .apply and .also, but to no avail.

解决方案

You can use the composed function:

Declare a just-in-time composition of a Modifier that will be composed for each element it modifies

Something like:

Box(modifierA.composed{ modifierB })

or

val modifierC = modifierA.composed{ modifierB }
Box(modifierC) {}

这篇关于如何连接单独声明的修饰符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆