簡體   English   中英

Jetpack Compose 中 ReplacementSpan 的替代方案?

[英]Alternatives to ReplacementSpan in Jetpack Compose?

我知道這個問題很模糊,可能沒有一個正確的答案。 我只是想聽到一些輸入並圍繞 Compose 中的高級文本樣式創建一些內容。 我希望一切順利。

有誰知道是否有辦法在撰寫中使用跨度? 我使用 Views 系統構建了一個自定義MultiAutocompleteTextView ,該系統使用ChipSpan(...): ImageSpan(...)創建芯片。

它看起來像這樣:

在此處輸入圖片說明

你會如何在 Compose 中處理這個問題? 任何輸入將不勝感激! 謝謝你。

InlineTextContent可能正是您要找的。 它使用AnnotatedString和占位符,並允許您在文本中插入 Composables:

val text = buildAnnotatedString {
    appendInlineContent("chip1", "Acid")
}

val inlineContent = mapOf(
  "chip1" to InlineTextContent(
    Placeholder(
        width = 1.em, // calculate text width
        height = 1.em, // calculate text height
        placeholderVerticalAlign = PlaceholderVerticalAlign.AboveBaseline
    )
  ) {
     // call chip composable
  }
)

BasicText(text = text, inlineContent = inlineContent)

如果您希望與 Text 一起使用,InlineTextContent 可能會很有用。 但是在 Textfield 的情況下,似乎還沒有實現。 查看在問題跟蹤器中提交的以下功能請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM