如何将Android小部件中的字体更改为应用“assets”文件夹中的用户定义字体?

问题描述:

我想更改我的小部件中的字体,使其在我的应用的“资产”文件夹中使用特定的字体。如何将Android小部件中的字体更改为应用“assets”文件夹中的用户定义字体?

我通常做这在我的应用程序来改变字体:

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

,它就像一个魅力。

我如何在小工具中做到这一点?我只能设置文本并更改颜色:

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

但我没有看到设置字体的方法。请帮忙吗?

遇到同样的问题,以及发现这一点: “因为小部件住在其他进程中,他们只能用系统 字体,而不是其他字体,可能是内部的 包的一种方式解决此会。在您的进程中将您的字体渲染到 位图,然后将其推送到RemoteViews中。“ 发布由杰夫·夏基这里: http://www.mailinglistarchive.com/html/[email protected]/2009-06/msg00211.html

用于控件的字体,这样一些预设,但只有 - 正常,SANS,衬线字体,等宽。我的例子

<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" />