I want to change the font of my textview from Roboto regular to roboto condensed. The textView is in a Widget and so i am using a RemoteView. If it is an application we can set it by typeFace. What i need to do for that ?
I have the answer now. What we have to do is render the font onto a canvas, and then pass it on to a bitmap and assign that to an imageview
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(),"robonto_condunced.ttf");
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setTypeface(clock);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(65);
paint.setTextAlign(Align.CENTER);
myCanvas.drawText(time, 80, 60, paint);
return myBitmap;
}
You just use typeface. Here is an example
private void setFonts() { // Setting all fonts
Typeface face = Typeface.createFromAsset(this.getAssets(),
"fonts/DroidSerif-Bold.ttf");
mMonthTextView.setTypeface(face);
mAgeTextView.setTypeface(face);
mHeightAndWeightTextView.setTypeface(face);
}
You must put that font in the Assets/fonts/ folder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With