问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/49521741/in-android-if-i-use-binding-how-to-apply-clickablespan