Java 不幸的是,我的应用程序停止工作了?
我试着向世界问好!通过在我的笔记本电脑中使用src/Main/CustomF/times.ttf中存储的自定义字体设计一个应用程序……执行时,它很快就会消失,告诉我不幸的是你的应用程序停止了……我的编码如下……请帮助我Java 不幸的是,我的应用程序停止工作了?,java,android,fonts,textview,typeface,Java,Android,Fonts,Textview,Typeface,我试着向世界问好!通过在我的笔记本电脑中使用src/Main/CustomF/times.ttf中存储的自定义字体设计一个应用程序……执行时,它很快就会消失,告诉我不幸的是你的应用程序停止了……我的编码如下……请帮助我 package com.example.nambimanavalan.customfonts; import android.app.Activity; import android.graphics.Typeface; import android.os.Bundle; im
package com.example.nambimanavalan.customfonts;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView t;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t=(TextView)findViewById(R.id.mine);
Typeface custom=Typeface.createFromAsset(getAssets(),"CustomF/times.ttf");
t.setTypeface(custom);
}
}
您需要将您的字体放在assets/font文件夹中,然后才能使用
Typeface custom=Typeface.createFromAsset(getAssets(),"Font/times.ttf");
将您的自定义字体放在:assets/CustomF/times.ttf中,也许这样它就可以工作了
“资产”文件夹直接位于您的项目文件夹下,每当您创建一个新项目时,它都是空的。显示堆栈跟踪-\您可以显示一些日志或堆栈跟踪吗?发布堆栈跟踪,并将fontfile放在项目中“资产”文件夹内的“Font”文件夹中