Ahmad..
9
有没有办法改变小部件中的字体?
是的,但不幸的是你只能使用系统字体.你可以在Android 4.1+上原生使用Roboto字体,但是:
android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
在以前版本的Text上使用Roboto的唯一方法是创建一个Bitmap并在Canvas上绘制Text,如下所示:
Bitmap myBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/myFont.ttf");
paint.setTypeface(font);
paint.setStyle(Paint.Style.FILL);
paint.setColor(...);
paint.setTextSize(...);
myCanvas.drawText("Hello World", x, y, paint);
然后将它设置为RemoteView:
rViews.setImageViewBitmap(R.id.myImageView, myBitmap);