2016-11-13 7 views
1

私はカスタムフォントのテキストビューを作りたがっていました。Fragment Android Studioでカスタムフォントが動作しない

私はFragEarnCredits.javaに持っている:

<TextView 
    android:id="@+id/logo" 
    android:text="Fashion Wallet" 
    android:gravity="center" 
    android:textSize="40dp" 
    android:textColor="@color/md_brown_700" 
    android:layout_marginTop="100dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    /> 

そして、私がnullエラーを取得しています:fragment_earn_credits.xml

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     if (aiView == null) { 
      aiView = inflater.inflate(R.layout.fragment_earn_credits, container, false); 
     } 


     t = (TextView) aiView.findViewById(R.id.logo); 
     Typeface myCustomFont=Typeface.createFromAsset(aiContext.getAssets(),"fonts/bebas.otf"); 
     t.setTypeface(myCustomFont); 

。どうして?みんな助けて!

Typeface myCustomFont=Typeface.createFromAsset(aiContext.getAssets(),"fonts/bebas.otf"); 

Typeface myCustomFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/bebas.otf"); 

そして0エラーが、フォントが変更されていません。

#EDIT

は私が変更しようとしました。

答えて

0
Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/customfont.ttf"); 

フラグメントクラスで送信するコンテキストは、実際のコンテキストを使用する必要があります。

希望すると助かります!乾杯!

+0

@aaooが動作しません。 0エラーが発生し、フォントが変更されていない –

+0

@FootballFan、別のフォントを試して、フォントファイルが大丈夫かどうか確認できますか? –

+0

@aaoo働いています、私はPhotoshopを使用しています –

関連する問題