2017-01-03 4 views
0

나는 나의 텍스트 뷰 중 하나에 대한 사용자 지정 글꼴을 만들고 싶어하지만 난 여전히 여기 사용자 정의 글꼴

cannot resolve method getAssets() 

이 코드의 일부이다 받고 있어요 :

@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 메서드 내에서 설정하는 대신 사용자 정의 textview 클래스에서 글꼴을 정의 할 수 있습니다.이 방법을 사용하면 메모리가 적어 지므로 앱 성능이 향상됩니다.

0

컨텍스트와 함께 getAssets를 호출 할 수 있습니다. 이것을 사용하십시오 :

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

행운을 빕니다.

0

당신이

이 아래가

사용 컨텍스트

이 글꼴에 따라 자산 폴더에 있는지 확인 변경합니까 코드에서 어댑터로 사용하려는으로 capture.ttf 파일

check 파일 캡처 경로 .ttf

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