Majjoodi
Majjoodi

Reputation: 171

How to change the font in Android widgets to user-defined fonts in "assets" folder of the app?

I want to change the font in my widget such that it uses a specific font in "assets" folder of my app.

I usually do this in my app to change the font:

        Typeface tf= Typeface.createFromAsset(getAssets(), "advertising.ttf");
        TextView converted = (TextView)findViewById(R.id.TextView03);
        converted.setTypeFace(tf);

and it works like a charm.

How can I do this in widgets? I can only set the text and change the color:

      remoteView.setTextViewText(R.id.TextView03,"some text" );
    remoteView.setTextColor(R.id.TextView03, Color.BLACK);

but I don't see a way to set the font. Any help please?

Upvotes: 6

Views: 5628

Answers (2)

pr.stas
pr.stas

Reputation: 29

for widget such a few presets for fonts, but only - normal, sans, serif, monospace. My example

<TextView  android:id="@+id/UniStringLineHeadTxtTime1" android:text="" android:layout_width="wrap_content" android:layout_height="14dp" android:textStyle="bold" android:typeface="normal" android:textSize="9dp" android:textColor="#F0F0F0" android:paddingLeft="2dp" android:paddingTop="1dp" />

Upvotes: 0

shaemus mcgoo
shaemus mcgoo

Reputation: 53

Ran into the same problem as well and found this: "Because widgets live in other processes, they can only use system typefaces, and not additional fonts that might be internal to your package. One way around this would be to render your font onto a Bitmap in your process, and then push it across RemoteViews." Posted by Jeff Sharkey here: http://www.mailinglistarchive.com/html/[email protected]/2009-06/msg00211.html

Upvotes: 4

Related Questions