Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing font from Roboto regular to Roboto condensed

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 ?

like image 912
Kamalone Avatar asked Feb 21 '12 11:02

Kamalone


2 Answers

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;
}
like image 189
Kamalone Avatar answered Nov 09 '22 02:11

Kamalone


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

like image 30
Zacharias Manuel Avatar answered Nov 09 '22 01:11

Zacharias Manuel