android-spannable

How to apply the background color for the ImageSpan in Android?

為{幸葍}努か 提交于 2020-03-02 12:22:28
问题 I want to apply the background color for the Image span dynamically in Android. Could you please suggest any ideas? 回答1: You can't use BackgroundColorSpan and ImageSpan at the same time. The idea is creating an ImageSpan from LayerDrawable with background and image layers. Please look at the following code: Kotlin: val span: Spannable = SpannableString("This is ic launcher with background") val myImage: Drawable = resources.getDrawable(R.drawable.ic_launcher_foreground) val background =