簡體   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