【发布时间】:2018-08-14 12:18:32
【问题描述】:
我开始从事 Android 开发,但遇到了一个问题......
我正在尝试在 Android Studio 中更改 Button 的字体,我已经密切关注了一些教程,但没有成功。
我遵循的教程:
Error trying to change font android studio
How to change the font on the TextView?
我没有收到任何错误消息,它只是不起作用。有谁知道我做错了什么?
代码:
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/jua.ttf");
Button Button = (Button) findViewById(R.id.Button)
Button.setTypeface(font);
XML:
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/my_button_bg"
android:text="Button"
android:textColor="@android:color/white"
android:textSize="15sp" />
文件夹结构图:
Structure of folder - image
【问题讨论】:
-
在最新的 android studio 中有一个单独的字体文件夹,您可以在其中定义自定义字体并通过设置 font-family 添加到 textview 或按钮
-
我建议你使用书法库来处理字体。它非常易于使用且重量轻。