繁体   English   中英

Jetpack Compose:检查文本最大行数

[英]Jetpack Compose :Check count of Text max lines

我有一个场景,如果文本最大行数超过 9,我需要显示一个按钮,否则按钮不应该出现。

我尝试查看开发人员 android 指南,但找不到任何解决方案。

下面是我的代码:

                    Text(
                        //text = item.content,
                        text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
                                "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, " +
                                "when an unknown printer took a galley of type and scrambled it to make a type specimen book. " +
                                "It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software " +
                                "like Aldus PageMaker including versions of Lorem Ipsum.",

                        modifier = Modifier
                            .padding(bottom = 4.dp),
                        fontSize = 16.sp,
                        //maxLines = 6,
                        textAlign = TextAlign.Start,
                        style = MaterialTheme.typography.body1,
                    )

                

以下对我有用:

Column {
    var textOverflow by remember { mutableStateOf(false) }
    Text(
        modifier = Modifier.size(50.dp),
        text = "1234567891",
        fontSize = 16.sp,
        maxLines = 2,
        onTextLayout = { textLayoutResult ->
            textOverflow = textLayoutResult.hasVisualOverflow
        },
        textAlign = TextAlign.Start,
        style = MaterialTheme.typography.body1,
    )
    if(textOverflow) {
        Button(onClick = {}) {
            Text("Hello")
        }
    }
}

暂无
暂无

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

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