get Image SpannableString - Android android.text

Android examples for android.text:SpannableString

Description

get Image SpannableString

Demo Code

import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.BackgroundColorSpan;
import android.text.style.CharacterStyle;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import android.view.View;

public class Main{

    public static SpannableString getImageSpan(Context context,
            String text, Bitmap bitmap) {
        SpannableString spanString = new SpannableString(text);
        spanString.setSpan(new ImageSpan(context, bitmap), 0,
                text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spanString;
    }//from  www. j  a va2 s .c o m
    public static SpannableString getImageSpan(Context context,
            String text, int resid) {
        SpannableString spanString = new SpannableString(text);
        spanString.setSpan(new ImageSpan(context, resid), 0, text.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spanString;
    }
    public static SpannableString getImageSpan(Context context,
            String text, Uri uri) {
        SpannableString spanString = new SpannableString(text);
        spanString.setSpan(new ImageSpan(context, uri), 0, text.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spanString;
    }

}

Related Tutorials