简体   繁体   English

改变从Roboto常规到Roboto的字体浓缩

[英]Changing font from Roboto regular to Roboto condensed

I want to change the font of my textview from Roboto regular to roboto condensed. 我想将我的textview的字体从Roboto常规更改为roboto浓缩。 The textView is in a Widget and so i am using a RemoteView. textView位于Widget中,因此我使用的是RemoteView。 If it is an application we can set it by typeFace. 如果它是一个应用程序,我们可以通过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 我们要做的是将字体渲染到画布上,然后将其传递给位图并将其分配给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 您必须将该字体放在Assets / fonts /文件夹中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM