简体   繁体   English

自定义字体按钮不起作用Android-Studio

[英]Custom font button not working Android-Studio

Hello I'm trying to use a Custom font to my Button I've added the font on res/assets. 您好,我试图在按钮上使用自定义字体,我在res / assets上添加了该字体。

On my .java I have this code 在我的.java上,我有此代码

      Button btjoc = (Button) findViewById(R.id.btJoc);
    Typeface font = Typeface.createFromAsset(getAssets(), "Heart Breaking Bad.ttf");
    btjoc.setTypeface(font);
    Button bttaula = (Button) findViewById(R.id.btTaula);
    bttaula.setTypeface(font);

And it doesn't work... I don't know if I have to put something else, wish you can help me... 而且它不起作用...我不知道我是否还要放些东西,希望您能帮助我...

Thanks. 谢谢。

Do you see any logcat error? 您是否看到任何logcat错误? Do you have related font in your assets directory? 您的资产目录中是否有相关的字体? try to change your font name in asset folder and your code to Heart_Breaking_Bad.ttf 尝试将资产文件夹中的字体名称更改为Heart_Breaking_Bad.ttf

you must moved it to main/assets instead of res/assets . 您必须将其移至main/assets而不是res/assets
and see my answer here , maybe help you. 在这里查看我的答案,也许可以帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM