可编辑的跨度位于editText的相同开始和结束位置.
sb.setSpan(cs,imageStartSpan,imageEndSpan,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
也
editText.setMovementMethod(LinkMovementMethod.getInstance());
我无法为你编写完整的代码.试试以下样本: –
public void addToEdt(Bitmap bitmap){
SpannableString ss = new SpannableString();
Drawable d = new BitmapDrawable(getResources(),d.getIntrinsicHeight());
ss.append("abc"); // Append the text here
ImageSpan span = new ImageSpan(d,2,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // start(0) and end (2) will create an image span over abc text
ss.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
ss.delete(0,2);
editText.setText(ss);
}
},Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // this will add a clickable span and on click will delete the span and text
editText.setText(ss); // this will show your image/clickable span in edittext
}
editText.setMovementMethod(LinkMovementMethod.getInstance());