Applying different fonts to text in a button in android

android, font-awesome, java

Solution

This is how I achieved it and used CustomTypefaceSpan Class from https://stackoverflow.com/a/10741161/992665

public class MainActivity extends Activity {

    Typeface tf_r, tf_icon;
    Button reload;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        int hexVal = Integer.parseInt("f021", 16);
        SpannableStringBuilder SS = new SpannableStringBuilder((char)hexVal + " Refresh");

        tf_r = Typeface.createFromAsset(this.getAssets(), "www/fonts/Roboto-Light.ttf");
        tf_icon = Typeface.createFromAsset(this.getAssets(), "www/fonts/fontawesome-webfont.ttf");

        SS.setSpan(new CustomTypefaceSpan("", tf_icon), 0, 1,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        SS.setSpan(new CustomTypefaceSpan("", tf_r), 1, 9,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);

        reload = (Button) findViewById(R.id.no_openings_reload);
        reload.setText(SS);
    }
}

Problem

I am creating an android button for reload. It want to have both icon and text in the button so I am using fontawesome. But how do I apply fontawesome font and custom font I am using in my app at same Time on the buttons text.

Original source

Related problems