0

I want to change the font of textview in Home screen widget?

            RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                R.layout.time_widget_layout);
        remoteViews.setTextViewText(R.id.tvTime, Utility.getCurrentTime("hh:mm:ss a"));

i have font in my assets folder.

M.ArslanKhan
  • 3,640
  • 8
  • 34
  • 56

2 Answers2

0

TextView has a method on it called setTypeface

The code to set the font would look similar to this if your font is at "Assets/Font/Font.otf":

Typeface font = Typeface.createFromAsset(context.getAssets(), "Font/Font.otf");
TextView textView = (TextView)findViewById(R.id.tvTime);
textView.setTypeface(font, Typeface.NORMAL);

Optional: If needed, you can do this inside the constructor of a class inheriting from TextView, then use that class in your layouts, in case you wanted to use that font in a bunch of different places. Also, if you wanted to do it inside the constructor, you could have the name of the font passed in as a styled attribute in your layout and use that instead of the hardcoded string like above.

CShark
  • 1,562
  • 1
  • 16
  • 27
-1

RemoteView methods are very limited. but setImageViewBitmap is enough.
create a TextView using java code, enable this features:

textView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
textView.setDrawingCacheEnabled(true);

now set typeFace,change font size and do whatever you want, at last you can get your desired Bitmap and set it to your home screen ImageView

textView.buildDrawingCache();
Bitmap finalResult = textView.getDrawingCache();
remoteImageView.setImageViewBitmap(R.id.ivWidget, finalResult);
Amir
  • 1,250
  • 18
  • 22