简体   繁体   中英

How to import font in Android studio

I am trying to change the font style in my Android App. So I copy and paste the font file (.ttf) into the assets folder. After pasting it show's File was loaded in the wrong encoding :UTF-8 . How can I solve it? (attached picture below)

Note : I already tried following ways.

a) convert file encoding to UTF-8

b) set the right file encoding in your build.gradle script.

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. I changed that in the File Type option in Settings and font was working fine.

Steps:

  1. Go to Settings
  2. Select File Type
  3. Search for .tff file
  4. Deactivate linking as text (it maybe some other type in your case)

Hope this solves your issue.

Thankyou @Sreeram TP. This post may help to resolve that problem completely. I show my solution below.

After deactivating linking as text (pic1 below) 停用链接作为文本

I deleted and re-pasted my font.ttf file. It then shows the following alert (pic2 below):

alert:注册新文件类型关联

I selected Open matching file in associated application .

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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