2011-09-24 87 views
0

我有一個問題,字體不起作用,它給了我一個FC。所以我把字體文件放到SD卡中,並在字體中使用CreateFromFile,字體工作!
這裏是我使用的資產文件夾代碼:Assets文件夾中的問題

 holder.tv_SuraName =(TextView)convertView.findViewById(R.id.Start_Name); 
    holder.tv_SuraName.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "suralist_font.ttf")); 

但我改變了代碼,這和它的工作:

  holder.tv_SuraName = (TextView)convertView.findViewById(R.id.Start_Name); 
     Typeface Font = Typeface.createFromFile(new File(Environment.getExternalStorageDirectory()+"/asd.ttf")); 

這是否意味着我必須在資產文件夾有問題?我怎樣才能解決這個問題?由於

+0

在你的代碼中你正在創建字體從文件你沒有設置字體爲textview你設置字體在textview肯定? – Dharmendra

回答

0

看到這個

Typeface font0 = Typeface.createFromAsset(getAssets(),"fonts/AmericanDream.ttf"); 
    tv1.setTypeface(font0); 

這裏字體(資產文件夾)文件夾中包含AmericanDream.ttf文件中。 like:assets - > fonts - > AmericanDream.ttf 我希望這會對你有所幫助。

+0

這個工作越來越字體..其怪,但現在它的工作原理..它是更好地從資產或從文件獲取字體? – Omar

+0

請投票並接受.. –

0
AssetManager assetManager1 = getApplicationContext().getAssets(); 
Typeface tf1 = Typeface.createFromAsset(assetManager1, "James_Fajardo.ttf"); 

和TextView中使用類似

urTextView.setTypeface(tf1, Typeface.BOLD); 

希望ü有用。

+0

我得到了同樣的錯誤「無法生成本地面型」 – Omar

+0

請確保您已將「suralist_font.ttf」文件放置在資產文件夾中,因爲如果文件不存在於資產中,而只會產生像「無法生成本地面型」 。我試過這個。 –

+0

我的確有這個文件有:(嗯,我想我會繼續從文件 – Omar