-
-
Save magicgoose/8b4bb1eb7ee428c0fc3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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