我正在尝试使用外部字体,我使用某人的答案(不记得从哪里),但它在开始时崩溃。
我基本上有一个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(访问被拒绝)