无法使用外部字体

时间:2017-03-12 19:40:01

标签: android custom-font

我正在尝试使用外部字体,我使用某人的答案(不记得从哪里),但它在开始时崩溃。

我基本上有一个assets / fonts文件夹,其中我放了一个font.ttf文件: https://i.gyazo.com/2010d3becbabbab35fc8738a6a30689b.png

这是TextView的XML代码:

    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Text Here."
    android:textSize="30dp"
    android:layout_marginTop="120dp"
    android:textAlignment="center"
    android:id="@+id/howtotv"/>

这是它的Java代码,我试图分配字体:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.howtoplay);
    MyTV = (TextView) findViewById(R.id.howtotv);
    Typeface typeface=Typeface.createFromAsset(getAssets(), "fonts/archristy.ttf");
    MyTV.setTypeface(typeface);
}

我得到的错误:

错误:任务':app:packageDebug'执行失败。

  

java.io.FileNotFoundException:D:\ AndroidStudioProjects \ Tapper2 \ app \ build \ intermediates \ assets \ debug \ fonts(访问被拒绝)

1 个答案:

答案 0 :(得分:0)

根据我的参考,

代码似乎很完美,请参阅链接agg

尝试清理一次项目并重建它。