2012-05-13 18 views
-1

由於Widget開發,我需要定義自己的字體(有時可以通過SharedProperties進行更改)。更改Android Widget資產目錄中的字體

一個FO我在這裏看到的soultion是使用:

TextView tv=(TextView)findViewById(R.id.yearthree_view); 
Typeface font = Typeface.createFromAsset(this.getAssets(), "fonts/Century_Gothic.ttf"); 
tv.setTypeface(font); 

但問題是:的onUpdate()方法不到風度熟悉

findViewById

我使用RemoteViews進入TextView以更新文本的方法。

在此先感謝。

回答

0

創建自定義TextView擴展TextView並在初始化時設置字體。

public class CustomTextView extends TextView { 

     public CustomTextView(Context context, AttributeSet attrs) { 
      super(context, attrs); 
      initTextFont(context); 
     } 

     public CustomTextView(Context context, AttributeSet attrs, int defStyle) { 
      super(context, attrs, defStyle); 
      initTextFont(context); 
     } 

     private void initTextFont(Context context) { 
      //Set font here. 
     } 

    } 
0

使用context.getassets() ; 上下文中的onUpdate

Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/Century_Gothic.ttf"); 
通過
相關問題