In Android, if I use binding, how to apply ClickableSpan?

℡╲_俬逩灬. 提交于 2019-12-25 01:35:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!