Java 向android应用程序添加自定义字体

Java 向android应用程序添加自定义字体,java,android,android-fonts,Java,Android,Android Fonts,我正在尝试将自定义字体添加到我的android应用程序中。这是我的密码。谁能告诉我哪里错了 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textview = (TextView) findV

我正在尝试将自定义字体添加到我的android应用程序中。这是我的密码。谁能告诉我哪里错了

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView textview = (TextView) findViewById(R.id.FontTest);

        Typeface tf = Typeface.createFromAsset(getApplicationContext()
                .getAssets(), "fonts/snap-itc.ttf");
        textview.setTypeface(tf);
    }

而不是:

Typeface tf = Typeface.createFromAsset(getApplicationContext()
                .getAssets(), "fonts/snap-itc.ttf");

这可能很明显,但请确保您的项目目录中有一个/assets/fonts文件夹,并且您的自定义字体就在那里。此外,检查字体的拼写是否正确(+是否为大写/小写),并更正代码中的拼写


这也可能意味着字体本身已损坏。

在应用程序中添加字体,如

 TextView txtvw=(TextView)findViewById(R.id.textviewname);

 Typeface typface=Typeface.createFromAsset(getAssets(),"fonts/burmese.ttf");

  txtvw.setTypeface(typface);

代码很好…您是否收到任何类型的错误或异常帖子,错误是“无法设置本机字体”。此外,您使用的IDE是什么?不再工作。错误是“无法设置本机字体”将您的ttf文件仅放在资产文件夹中。然后将其作为
Typeface tf=Typeface.createFromAsset(getAssets(),“snap itc.ttf”)获取
Typeface tf = Typeface.createFromAsset(getApplicationContext()
                .getAssets(), "fonts/snap-itc.ttf");
 TextView txtvw=(TextView)findViewById(R.id.textviewname);

 Typeface typface=Typeface.createFromAsset(getAssets(),"fonts/burmese.ttf");

  txtvw.setTypeface(typface);