Use of textview SpannableString and ImageSpan classes in android
Today I will explain the SpannableString and ImageSpan classes.
Bitmap bitmap = null;
Bitmap = BitmapFactory. decodeResource (getResources (), imageIds [arg2% imageIds. length]);
// The first parameter includes the entire image resource and the second specified id
ImageSpan imageSpan = new ImageSpan (NeighborCommunicationMessageActivity. this, bitmap );
// Add the class used by the image in the editing box to replace the specified text with the image. For example, you can replace the image with each other. You will be asked to select
String str = null;
If (arg2 <10 ){
Str = "f00" + arg2;
} Else if (arg2 <100 ){
Str = "f0" + arg2;
} Else {
Str = "f" + arg2;
}
SpannableString spannableString = new SpannableString (str );
SpannableString. setSpan (imageSpan, 0, 4, Spannable. SPAN_EXCLUSIVE_EXCLUSIVE );
//
Content. append (spannableString );
TextView and SpannableString use Daquan there is a text replaced with ImageSpan specifically: SpannableString ss = new SpannableString ("ccccccccccccccc step on ");
Drawable d = getResources (). getDrawable (R. drawable. icon );
D. setBounds (0, 0, d. getIntrinsicWidth (), d. getIntrinsicHeight ());
// Create ImageSpan
ImageSpan span = new ImageSpan (d, ImageSpan. ALIGN_BASELINE );
// Replace text with ImageSpan
Ss. setSpan (span, 18, 19, Spannable. SPAN_INCLUSIVE_EXCLUSIVE );
TxtInfo. setText (ss );
At this time, content. append (spannableString) is actually passing the image expression into edittext.