create Background Color Span - Android Graphics

Android examples for Graphics:Spannable Color

Description

create Background Color Span

Demo Code


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextPaint;
import android.text.style.BackgroundColorSpan;
import android.text.style.CharacterStyle;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
import android.text.style.TypefaceSpan;
import android.text.style.UnderlineSpan;
import android.util.TypedValue;
import android.view.View;

public class Main{
    public static CharacterStyle createBackgroundColorSpan(
            final Context context, int colorResId) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return createBackgroundColorSpan(context.getColor(colorResId));
        } else {//  ww w. j  a va2s . co m
            //noinspection deprecation
            return createBackgroundColorSpan(context.getResources()
                    .getColor(colorResId));
        }
    }
    public static CharacterStyle createBackgroundColorSpan(int color) {
        return new BackgroundColorSpan(color);
    }
}

Related Tutorials