Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's a little old, but I improved the class CustomFontLoader a little bit and I wanted to share it so it can be helpfull. Just create a new class with this code.</p> <pre><code> import android.content.Context; import android.graphics.Typeface; public enum FontLoader { ARIAL("arial"), TIMES("times"), VERDANA("verdana"), TREBUCHET("trbuchet"), GEORGIA("georgia"), GENEVA("geneva"), SANS("sans"), COURIER("courier"), TAHOMA("tahoma"), LUCIDA("lucida"); private final String name; private Typeface typeFace; private FontLoader(final String name) { this.name = name; typeFace=null; } public static Typeface getTypeFace(Context context,String name){ try { FontLoader item=FontLoader.valueOf(name.toUpperCase(Locale.getDefault())); if(item.typeFace==null){ item.typeFace=Typeface.createFromAsset(context.getAssets(), "fonts/"+item.name+".ttf"); } return item.typeFace; } catch (Exception e) { return null; } } public static Typeface getTypeFace(Context context,int id){ FontLoader myArray[]= FontLoader.values(); if(!(id&lt;myArray.length)){ return null; } try { if(myArray[id].typeFace==null){ myArray[id].typeFace=Typeface.createFromAsset(context.getAssets(), "fonts/"+myArray[id].name+".ttf"); } return myArray[id].typeFace; }catch (Exception e) { return null; } } public static Typeface getTypeFaceByName(Context context,String name){ for(FontLoader item: FontLoader.values()){ if(name.equalsIgnoreCase(item.name)){ if(item.typeFace==null){ try{ item.typeFace=Typeface.createFromAsset(context.getAssets(), "fonts/"+item.name+".ttf"); }catch (Exception e) { return null; } } return item.typeFace; } } return null; } public static void loadAllFonts(Context context){ for(FontLoader item: FontLoader.values()){ if(item.typeFace==null){ try{ item.typeFace=Typeface.createFromAsset(context.getAssets(), "fonts/"+item.name+".ttf"); }catch (Exception e) { item.typeFace=null; } } } } } </code></pre> <p>Then just use this code on you textview:</p> <pre><code> Typeface typeFace=FontLoader.getTypeFace(context,"arial"); if(typeFace!=null) myTextView.setTypeface(typeFace); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload