将RelativeSizeSpan 与TextView 的textAllCaps 一起使用为true 不起作用

mva*_*and 2 android spannable

都在标题里了。

这是一个错误还是一个期望的行为?在最后一种情况下,我不明白为什么?

Nik*_*ski 5

可能是错误或互斥。

textAllCaps设置适用TextViewTransformationMethod,它会获取文本并将其转换为纯文本Strings,从而使源文本CharSequence失去所有其他样式和跨度。

你可以像(Kotlin naive)一样以编程方式欺骗它:

 val text = textView.text // at this point allCaps is applied so text is caps
 textView.setAllCaps(false) // remove the allCaps
 val spannable = SpannableString(text) // create new spannable with allCapped text 
 spannable.setSpan(RelativeSizeSpan(1f), 0, text.length, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE)
 textView.text = spannable //set it.
Run Code Online (Sandbox Code Playgroud)

另一种方法是创建您自己的方法TransformationMethod,将您的跨度应用于设置的每个文本。