2017-01-03 10 views
0

は、コードの一部です:カスタムフォント

@Override 
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    final String childText = (String)getChild(groupPosition, childPosition); 
    if (convertView == null) { 
     LayoutInflater infalInflater = (LayoutInflater)this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = infalInflater.inflate(R.layout.list_item, parent, false); 
    } 
    Utils.setFontAllView((ViewGroup)convertView); 

    TextView txtListChild = (TextView)convertView.findViewById(R.id.txtcardname); 
    txtListChild.setTypeface(null, Typeface.BOLD); 

    TextView kategoria = (TextView)convertView.findViewById(R.id.kategoria); 
    kategoria.setText(this.KATEGORIE[numerKategori]); 


    custom_font = Typeface.createFromAsset(getAssets(), "fonts/capture.ttf"); 
    txtListChild.setTypeface(custom_font); 

は私が作りたいですそれこのコードで:

custom_font = Typeface.createFromAsset(getAssets(), "fonts/capture.ttf"); 
     txtListChild.setTypeface(custom_font); 

答えて

0

はそれが動作します。このようにコードを更新します。

custom_font = Typeface.createFromAsset(mContext.getAssets(), "fonts/capture.ttf"); 

ビューのコンテキストなしでアセットにアクセスすることはできません。したがってコンテキストは必須です

getviewメソッド内のフォントを設定する代わりに、カスタムテキストビュークラスのフォントを定義することができます。これを使用すると、メモリが少なくて済み、アプリのパフォーマンスが向上します。

0

getAssetsをコンテキストで呼び出すことができます。これを使用:

custom_font = Typeface.createFromAsset(this._context.getAssets(), "fonts/capture.ttf"); 

幸運。

0

あなたのコード

からアダプターにそれを使用するようにしてください下にはあり、フォントの下で、あなたの資産フォルダに確認してください

使用コンテキスト

を変更しますcapture.ttfのファイル

ファイルキャプチャのパスを確認します。

Context context = null; 
      Typeface custom_font = Typeface.createFromAsset(context.getAssets(), "fonts/capture.ttf"); 
     txtListChild.setTypeface(custom_font);