[英]How to import font in Android studio
I am trying to change the font style in my Android App. 我正在尝试更改Android应用程序中的字体样式。 So I copy and paste the font file (.ttf) into the assets folder.
所以我将字体文件(.ttf)复制并粘贴到assets文件夹中。 After pasting it show's File was loaded in the wrong encoding :UTF-8 .
粘贴后,show的文件加载了错误的编码:UTF-8 。 How can I solve it?
我该如何解决? (attached picture below)
(下图)
Note : I already tried following ways. 注意:我已经尝试过以下方法。
a) convert file encoding to UTF-8 a)将文件编码转换为UTF-8
b) set the right file encoding in your build.gradle script. b)在build.gradle脚本中设置正确的文件编码。
But the problem is not solved yet. 但问题还没有解决。 It still shows encode formats error.
它仍然显示编码格式错误。
I faced similar issue when I was playing with fonts. 我在玩字体时遇到了类似的问题。 I think you are facing the same issue.
我认为你面临同样的问题。 In my Android Studio .tff file was linked to a text file.
在我的Android Studio .tff文件中链接到文本文件。 I changed that in the File Type option in Settings and font was working fine.
我在设置中的文件类型选项中更改了它,字体工作正常。
Steps: 脚步:
Hope this solves your issue. 希望这能解决您的问题。
Thankyou @Sreeram TP. 谢谢你@Sreeram TP。 This post may help to resolve that problem completely.
这篇文章可能有助于彻底解决这个问题。 I show my solution below.
我在下面展示我的解决方案
After deactivating linking as text (pic1 below) 停用链接后作为文本(下面的图1)
I deleted and re-pasted my font.ttf
file. 我删除并重新粘贴了我的
font.ttf
文件。 It then shows the following alert (pic2 below): 然后它显示以下警报(下面的图2):
I selected Open matching file in associated application . 我选择了相关应用程序中的Open匹配文件 。
This solved my problem completely. 这完全解决了我的问题。
It is not a problem actually. 实际上这不是问题。 You can still use the custom font like this :
你仍然可以使用这样的自定义字体:
TextView text = (TextView) findViewById(R.id.custom_text); Typeface font = Typeface.createFromAsset(getAssets(), "yourfont.ttf"); text.setTypeface(font);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.