我创建了以下名为
的按钮Button loginButton = (Button) findViewById(R.id.login_button);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Lato-Regular.ttf");
loginButton.setTypeface(tf);
我确保字体在资产/字体下。确切的文件名是:/Users/myusername/Documents/GitHub/appname/app/src/main/assets/fonts/Lato-BoldItalic.ttf。
但是,按钮上的字体仍然不会改变。这可能是什么问题?
编辑:扩展代码
protected void onCreate(Bundle savedInstanceState) {
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("###")
.server("https://parseapi.back4app.com/")
.clientKey("###")
.enableLocalDataStore()
.build()
);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button loginButton = (Button) findViewById(R.id.login_button);
Typeface tf = Typeface.createFromAsset(getAssets(), "Lato-Regular.ttf");
loginButton.setTypeface(tf);
more stuff
答案 0 :(得分:0)
将您的字体文件放在Assets文件夹中,然后尝试像这样访问
在以下树结构中创建资产文件夹
https://EXTERNAL-REAL-IP/test
然后将您的字体文件放在内部资产文件夹
--\app
-----\src
----------\main
--------------\assets
希望它会帮助你..
答案 1 :(得分:0)
代码中的字体名称(Lato-Regular.ttf
)与文件系统中的名称(Lato-BoldItalic.ttf
)不同。
此外,Android无法处理所有可能的字体。在这些情况下,它会悄然失败并默认为常规字体。您可能需要尝试其他字体。
答案 2 :(得分:0)
在设置Lato-BoldItalic.ttf
时,您已从文件夹中说fonts/Lato-Regular.ttf
。编辑你的代码!设置已添加到项目中的所需字体。