在EditText或者TextView中插入图片

2019-04-15 17:47发布

在EditText和TextView中插入图片主要用到SpannableString   SpannableString ss = new SpannableString("pic"); Drawable d = getResources().getDrawable(R.drawable.icon); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); ss.setSpan(span, 0, ss.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); typeEditText.append(ss);