Custom Fonts and Custom Textview on Android

The constructor of TextView calls setTypeface(Typeface tf, int style) with the style parameter retrieved from the XML attribute android:textStyle. So, if you want to intercept this call to force your own typeface you can override this method as follow: public void setTypeface(Typeface tf, int style) { Typeface normalTypeface = Typeface.createFromAsset(getContext().getAssets(), “font/your_normal_font.ttf”); Typeface boldTypeface = Typeface.createFromAsset(getContext().getAssets(), … Read more

custom font in android ListView

If you don’t want to create a new class you can override the getView method when creating your Adapter, this is an example of a simpleAdapter with title and subtitle: Typeface typeBold = Typeface.createFromAsset(getAssets(),”fonts/helveticabold.ttf”); Typeface typeNormal = Typeface.createFromAsset(getAssets(), “fonts/helvetica.ttf”); SimpleAdapter adapter = new SimpleAdapter(this, items,R.layout.yourLvLayout, new String[]{“title”, “subtitle” }, new int[] { R.id.rowTitle, R.id.rowSubtitle }){ … Read more

Use Roboto font in app with minimum API level 14

Is there a way to use Roboto without including the Roboto font as an asset? No there is no other way of doing this for API 11<. I usually create a custom TextView for the Robot typeface: public class TextView_Roboto extends TextView { public TextView_Roboto(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); createFont(); … Read more

How to use a custom typeface in a widget?

What is needed is to render the font onto a canvas, and then pass it on to a bitmap and assign that to an ImageView. Like so: public Bitmap buildUpdate(String time) { Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444); Canvas myCanvas = new Canvas(myBitmap); Paint paint = new Paint(); Typeface clock = Typeface.createFromAsset(this.getAssets(),”Clockopia.ttf”); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setTypeface(clock); … Read more