1

我有一个字体文件 love.ttf (5mb)。我已将其放入资产文件夹中。这是我的代码

 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView tv=(TextView)findViewById(R.id.textView1);
    Typeface tf=Typeface.createFromAsset(getAssets(),"love.ttf");;
    tv.setTypeface(tf,Typeface.NORMAL);
    tv.setTextSize(20);
}  

main.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#4B67A1"
    android:orientation="vertical" >    
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="おはようございます。" />    
</LinearLayout>

运行的时候看不到文字!!!如何加载大字体?请帮我!谢谢

4

2 回答 2

2

So, there will be firstly two possible reason why it doesn't work.

  1. Check if your font supports Japanese characters.
  2. You could have bad path of your font file.

    TextView tv = (TextView) findViewById(R.id.textView1);
    Typeface tf=Typeface.createFromAsset(getAssets(),"fonts/love.ttf");
    

You should have in your assets folder next subfolder named fonts. Then also check if you have correct suffix of font.

于 2012-06-16T13:57:07.263 回答
0

I would suggest you to not directly save font in Asset folder,rather create fonts folder under it and inside that save love.ttf font.

Then you can perform the magic as below.

  TextView tv=(TextView)findViewById(R.id.custom); 
  Typeface face=Typeface.createFromAsset(getAssets(), "fonts/love.ttf"); 
  tv.setTypeface(face); 
于 2012-06-16T14:02:54.190 回答