Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.drawable.Drawable;

import android.text.SpannableString;
import android.text.Spanned;

import android.text.TextUtils;

import android.text.style.ImageSpan;

public class Main {
    public static SpannableString setTextImg(String content, int startIndex, int endIndex, Drawable drawable) {
        if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
                || startIndex >= endIndex) {
            return null;
        }

        SpannableString spannableString = new SpannableString(content);
        spannableString.setSpan(new ImageSpan(drawable), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        return spannableString;
    }
}