2012-05-13 1 views
-1

ウィジェットの開発のために、自分のフォントの定義に依存しています(時々SharedPropertiesで変更できます)。アンドロイドのアセットディレクトリのフォントを変更するウィジェット

私はここで見たsoultion foの一つは、使用することです:

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

しかし、問題は次のとおりです。にonUpdate()メソッドは

に精通dosn't findViewById

マイテキストを更新するためにRemoteViewを使ってTextViewにアクセスするアプローチ。

ありがとうございます。

答えて

0

カスタムTextViewを作成するとTextViewが拡張され、初期化時にTypefaceが設定されます。

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() ; コンテキストは

Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/Century_Gothic.ttf"); 
にonUpdate

に渡されます
関連する問題