我想将我的文本视图的字体从Roboto regular更改为roboto condensed。textView在一个小部件中,所以我使用了一个RemoteView。如果它是一个应用程序,我们可以通过typeFace设置它。我需要为此做些什么?
发布于 2012-03-20 13:07:41
我现在有答案了。我们要做的是将字体渲染到画布上,然后将其传递给位图,并将其分配给图像视图
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;
}发布于 2012-02-21 19:08:26
你只需要使用字体。下面是一个例子
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);
}您必须将该字体放在Assets/fonts/文件夹中
https://stackoverflow.com/questions/9376408
复制相似问题