简体   繁体   English

Android Studio无法识别字体

[英]Fonts are not recognized at Android Studio

My Android Studio doesn't recognize fonts in .ttf or .otf format. 我的Android Studio无法识别.ttf或.otf格式的字体。 I searched for them at File--> Settings -->File Types , but there i can't find a category which recognizes this formats... Am I alone with this problem? 我在“文件”->“设置”->“文件类型”中搜索了它们,但是在这里找不到可以识别这种格式的类别...我一个人遇到这个问题吗?

Because of my new Membership I can't upload any pics, so here a link to a picture of my problem 由于我的新会员资格,我无法上传任何图片,因此,这里有指向我的问题图片的链接

http://fs2.directupload.net/images/141222/r23r74to.jpg

It is common for android studio (even in latest version) . 这对于android studio来说很常见(即使是最新版本)。 I also have "?" 我也有 ”?” mark in project explorer, however it is not problem in programming. 在项目资源管理器中标记,但是在编程中不是问题。

You can use your custom fonts directly in java. 您可以直接在Java中使用自定义字体。 First get a reference to the TextView displaying the text that you want to apply your custom font to. 首先获得对TextView的引用,该TextView显示了您要将自定义字体应用于的文本。 Then call the TypeFace class's createFromAsset() method to create a new type face using your custom font. 然后调用TypeFace类的createFromAsset()方法,以使用自定义字体创建新的字体。 You pass an instance of the app's AssetManager as the first parameter by calling getAssets() . 通过调用getAssets()将应用程序的AssetManager的实例作为第一个参数getAssets() This enables you to access the custom font asset file which you pass as the second parameter. 这使您可以访问作为第二个参数传递的自定义字体资产文件。

Finally, call setTypeFace() to apply your custom font to the text. 最后,调用setTypeFace()将自定义字体应用于文本。

TextView  textViewCustom= (TextView)findViewById(R.id.textCustomViewFont);
Typeface custom_font = Typeface.createFromAsset(getAssets(),"fonts/xyz.ttf");
   textViewCustom.setTypeface(custom_font);

Android custom fonts tutorial TypeFace java Android自定义字体教程TypeFace Java

Create a new TypeFace using your custom font, xyz.ttf which is saved in the assets/fonts folder. 使用自定义字体xyz.ttf创建一个新的TypeFace ,该字体保存在assets/fonts文件夹中。 You can do it in XML also. 您也可以用XML来实现。

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

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