在Android中,如果我使用绑定,如何应用ClickableSpan? [英] In Android, if I use binding, how to apply ClickableSpan?
问题描述
我知道如果不应用绑定,那么我可以使用Textview.setText(ClickableSpan)
来应用spannig效果以使部分文本可单击.但是,我的应用程序使用了绑定,并且textview的文本绑定到了像android:text="@{model.certainString}"
这样的xml内的xml中的ViewModel上,并且在我声明为String certainString = ""
的ViewModel中,在这种情况下我该如何在ViewModel内应用跨度呢?
I know that if binding is not applied, then I can use Textview.setText(ClickableSpan)
to apply spannig effect to make part of the text clickable. However, my app used binding and the textview's text is binded to a ViewModel inside xml like android:text="@{model.certainString}"
and in the ViewModel I declared String certainString = ""
, in this case how do I apply spanning inside the ViewModel then?
推荐答案
您可以在Adapter代码中编写自己的BindingAdapter来接受模型或字符串值,然后便可以应用Spannable.
You could write your own BindingAdapter which accepts either the model or the string value, within the Adapter code you would then be able to apply a Spannable.
https://developer.android.com/reference/android/databinding/BindingAdapter.html
这篇关于在Android中,如果我使用绑定,如何应用ClickableSpan?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!