Change font from Roboto to Roboto

I want to change the font of my text box from Roboto to compress the ends with roboto. TextView is in widgets, so I use RemoteView. If this is an application, we can install it using typeFace. What do I need to do for this?

+6
source share
2 answers

Now I have an answer. We need to make a font on the canvas, and then transfer it to a bitmap and assign it to the image

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; } 
+3
source

You just use a font. 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 should put this font in Assets / fonts / folder

+1
source

Source: https://habr.com/ru/post/908961/


All Articles