Androi Studio 无法识别注释中的键和值参数

问题描述 投票:0回答:1

我正在使用字符串资源中的 Spannable 字符串,但是当我尝试获取我的键和值时,注释无法识别这个字符串。

<string name="terms_conditions_prompt" formatted="true">Click to accept the <annotation action="openTC">terms and conditions</annotation></string>



val termsText = getText(R.string.terms_conditions_prompt) as SpannedString
val annotations = termsText.getSpans(0, termsText.length, Annotation::class.java)


val termsCopy = SpannableString(termsText)

for (annotation in annotations) {
    if (annotation.key == "action") {
        termsCopy.setSpan(
            createClickSpan(annotation.value),
            termsText.getSpanStart(annotation),
            termsText.getSpanEnd(annotation),
            SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
        )
    }
}

android kotlin annotations
1个回答
0
投票

您可能只是使用了错误的

Annotation
类导入,这就是为什么找不到
key
value
属性,因为导入的类没有这些。

确保您正在使用

import android.text.Annotation

© www.soinside.com 2019 - 2024. All rights reserved.