Blankj / AndroidUtilCode

:fire: Android developers should collect the following utils(updating).
https://blankj.com/2016/07/31/android-utils-code/
Apache License 2.0
33.32k stars 10.69k forks source link

SpanUtils中无法为appendImage的图片添加点击事件 #946

Closed open9527 closed 5 years ago

open9527 commented 5 years ago

Describe the bug

A clear and concise description of what the bug is.

The code of bug

无法响应点击事件

put your code here
SpanUtils.with(textView)
                .appendImage(R.mipmap.ic_launcher_round)
                .setClickSpan(new ClickableSpan() {
                    @Override
                    public void onClick(View view) {
                        LogUtils.i(TAG, "这是图片,添加点击事件");
                    }
                })
                .create();

## The stack of crash

<!-- e.g. 
-->

put the stack of crash here



## Screenshots

If applicable, add screenshots to help explain your problem.

Please delete the current line and the followings.

Thank you for supporting [AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode).
Blankj commented 5 years ago

https://github.com/Blankj/AndroidUtilCode/issues/504 这两个属性设置了吗,貌似新版本我已经封装进去了,图片点击事件我没试过

open9527 commented 5 years ago

文本是可以的,但是图片是不行

Blankj commented 5 years ago

给你个解决方案

var create = SpanUtils()
        .appendImage(R.drawable.span_shape_block_high, SpanUtils.ALIGN_BOTTOM)
        .create()
SpanUtils.with(spanAboutTv)
        .append(create)
        .setClickSpan(object: ClickableSpan() {
            override fun onClick(widget: View?) {
                ToastUtils.showLong("haha")
            }
        }).create()

后续我看有没有啥解决方案

Blankj commented 5 years ago

@open9527 1.24.6 版本已支持点击事件

shenjiabing commented 4 years ago

有没有办法使用spanUtils实现图文混排啊,需求是聊天室消息列表,用户头像+昵称+消息内容,用户头像是网络图片

Blankj commented 4 years ago

图片下载到本地,使用 bitmap 即可