Android 如何检查编辑文本是否具有可绘制性

Android 如何检查编辑文本是否具有可绘制性,android,Android,我正在使用SpannableStringBuilder在编辑文本中添加图像。但我的问题是如何检测编辑文本是否仍然包含图像?i、 我有一个既有图像又有文本的编辑文本,然后我删除图像,只保留文本。现在我想检查我的编辑文本是否仍然有图像 我正在使用这些代码将文本添加到编辑文本中 final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),options); getRoundedCornerBitmap(bitmap, Color.B

我正在使用SpannableStringBuilder在编辑文本中添加图像。但我的问题是如何检测编辑文本是否仍然包含图像?i、 我有一个既有图像又有文本的编辑文本,然后我删除图像,只保留文本。现在我想检查我的编辑文本是否仍然有图像

我正在使用这些代码将文本添加到编辑文本中

final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),options);
getRoundedCornerBitmap(bitmap, Color.BLUE,2,2,context);
String prevText = composeMessage.getText().toString();
SpannableStringBuilder ss = new SpannableStringBuilder(" \n" + prevText); 
Drawable d = new BitmapDrawable(getResources(),(Bitmap.createScaledBitmap(mmsPhoto, 120, 120, false)));

d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); 
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); 
ss.setSpan(span, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
composeMessage.setText(ss);

使用以下方法:

public boolean hasImageSpan(EditText editText) {
    Editable text  = editText.getEditableText();
    ImageSpan[] spans = text.getSpans(0, text.length(), ImageSpan.class);
    return !(spans.length == 0);
}

ss.getSpans()是您的朋友我如何吐司或记录此方法的返回?您可以执行如下操作:
log.I(“SPAN”,“Has Drawable?”:“+hasImageSpan(composeMessage))
基本上,获取
composeMessage
中的所有图像跨度,并查看
length==0
<代码>0表示内部没有图像。。