2015-03-25 63 views
0

我試圖使用自定義字體在片段一個TextView,但電話(4.4.2),我的應用程序崩潰,但有沒有顯示在Android Studio中字體 - 碎片碰撞我的應用程序上的設備

任何錯誤
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

    Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/androidnation_b.ttf"); 
    TextView txt = (TextView) getActivity().findViewById(R.id.textView1); 
    txt.setTypeface(font); 

    return inflater.inflate(R.layout.activity_fragment, container, false); 
} 

當我回復inflater應用程序之前評論這三行。 我正在尋找近一週的解決方案,但沒有任何幫助!

這裏是我的TTF路徑:項目 - >的src/main /資產/字體/ androidnation_b.ttf

我在使用該ID(textView1) 任何想法fragment_layout視圖如何解決這將是巨大的。

回答

2

下面是解不喜歡它

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

View v=inflater.inflate(R.layout.activity_fragment, container, false); 

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

TextView txt = (TextView) v.findViewById(R.id.textView1); 
txt.setTypeface(font); 

return v; 
} 
+0

TNX隊友,那工作 – KiZo 2015-03-25 11:55:20

0

嘗試這樣做是這樣的:

View view = inflater.inflate(R.layout.activity_fragment, container, false); 
Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/androidnation_b.ttf"); 
TextView txt = (TextView) view.findViewById(R.id.textView1); 
txt.setTypeface(font); 

return view; 
+0

謝謝U,它的工作原理:) – KiZo 2015-03-25 11:55:34