I'M trying to write a widget. There ise a linear layout and textview in activity. I want to show remaining time with textview. And I want to change my widget's font-face.
I successed to change Imageview's font-face, but when I'm trying to change textview font-face, I'm getting an error.
My Code:
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");
Error Log:
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
And "problem loading widget" is writing in widget area.
Tried: http://www.tristanwaddington.com/2012/09/android-textview-with-custom-font-support/ - yes, it was worked in normal activity but not in widget activity :S
and this code;
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);
this code is changing imageview's font-face but I'M getting an error with textview.
Best Regards..