我正在尝试编写一个小部件。活动中有线性布局和文本视图。我想用textview显示剩余时间。我想改变我的小部件的font-face。
我成功改变了Imageview的font-face,但是当我尝试更改textview font-face时,我收到了错误。
我的代码:
Bitmap myBitmap = Bitmap.createBitmap(80, 30, Bitmap.Config.ARGB_4444);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/Harngton.ttf");
paint.setTypeface(font);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(12);
myCanvas.drawText("MUSTAFA", 10, 20, paint);
try {
Log.d("DEBUG_LOG","Before.....");
remoteViews.setImageViewBitmap(R.id.label, myBitmap);
Log.d("DEBUG_LOG","After......");
} catch (Exception e) {
// TODO: handle exception
Log.d("DEBUG_LOG","Error message:" + e.getMessage());
}
Log.d("DEBUG_LOG","Hello! Outside try catch");
错误日志:
03-29 20:41:49.651: D/DEBUG_LOG(21519): Before.....
03-29 20:41:49.651: D/DEBUG_LOG(21519): After......
03-29 20:41:49.651: D/DEBUG_LOG(21519): Hello! Outside try catch
03-29 20:41:56.591: D/DEBUG_LOG(21519): Before.....
03-29 20:41:56.591: D/DEBUG_LOG(21519): After......
03-29 20:41:56.591: D/DEBUG_LOG(21519): Hello! Outside try catch
“问题加载小部件”正在小部件区域中写入。
尝试: http://www.tristanwaddington.com/2012/09/android-textview-with-custom-font-support/ - 是的,它在正常活动中工作但在小部件活动中没有工作:S
和这段代码;
Bitmap myBitmap = Bitmap.createBitmap(80, 30, Bitmap.Config.ARGB_8888);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/Harngton.ttf");
paint.setTypeface(font);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(12);
myCanvas.drawText("MUSTAFA", 30, 20, paint);
remoteViews.setImageViewBitmap(R.id.txtTime, myBitmap);
此代码正在更改imageview的font-face但我在使用textview时遇到错误。
最诚挚的问候..