【问题标题】:Unfortunately my app stopped working? [duplicate]不幸的是我的应用程序停止工作? [复制]
【发布时间】:2015-01-29 08:06:38
【问题描述】:

我尝试显示“hello world!”通过使用存储在我的笔记本电脑中的 src/Main/CustomF/times.ttf 中的自定义字体设计应用程序.....执行时它很快就会消失,告诉您“不幸的是,您的应用程序停止了”....我的编码如下.....请帮帮我..

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);

    }
}

【问题讨论】:

  • 显示堆栈跟踪-_-
  • 你能显示一些 logcat 或 stacktrace 吗?
  • 发布您的堆栈跟踪

标签: java android fonts textview typeface


【解决方案1】:

您需要将字体放在 assets/Font 文件夹中,然后才能使用

 Typeface custom=Typeface.createFromAsset(getAssets(),"Font/times.ttf");

【讨论】:

  • 并将您的字体文件放在项目资产文件夹内的“字体”文件夹中
【解决方案2】:

将您的自定义字体放入:assets/CustomF/times.ttf,然后它可能会起作用

assets 文件夹直接在您的项目文件夹下,每当您创建一个新项目时,它都是空的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    相关资源
    最近更新 更多