Skip to content

Instantly share code, notes, and snippets.

@magicgoose
Created May 18, 2015 08:37
Show Gist options
  • Save magicgoose/8b4bb1eb7ee428c0fc3b to your computer and use it in GitHub Desktop.
Save magicgoose/8b4bb1eb7ee428c0fc3b to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.CharacterStyle;
import android.text.style.ImageSpan;
import android.widget.TextView;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.iconics.typeface.IIcon;
public class IconUtil {
public static Spanned getIconSpanned(final IIcon icon, final TextView targetTextView) {
return getIconSpanned(
icon, (int) targetTextView.getTextSize(), targetTextView.getContext());
}
public static Spanned getIconSpanned(final IIcon icon, final int absoluteSize, final Context context) {
final IconicsDrawable iconDrawable =
new IconicsDrawable(context, icon).sizePx(absoluteSize);
final CharacterStyle s = new ImageSpan(iconDrawable);
final SpannableString ss = new SpannableString("{icon}");
ss.setSpan(s, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return ss;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment