2012-02-21 45 views
6

我想将我的textview字体从Roboto定期更改为roboto浓缩版。 textView位于Widget中,所以我使用的是RemoteView。如果它是一个应用程序,我们可以通过typeFace来设置它。我需要为此做些什么?从Roboto经常更改字体到Roboto浓缩

回答

3

我有答案了。我们要做的是将字体渲染到画布上,然后将其传递给位图并将其分配给图像视图

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; 
} 
1

你只是使用字体。下面是一个例子

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); 

} 

你必须把该字体的资产/字体/文件夹

+0

我正在使用RemoteView作为控件。所以我不能直接在我的代码中获取textview。我们不能直接在xml中设置字体类型吗? – Kamalone 2012-02-21 11:11:35

+0

我认为这是不可能的。我们只能将样式改为粗体或斜体。如果你想在XML中做到这一点,你必须创建一个自定义的文本视图。但这需要一段时间才能完成。 – 2012-02-21 11:15:02

相关问题