无法解析方法'getFont(?)' [英] cannot resolve method 'getFont(?)'

查看:903
本文介绍了无法解析方法'getFont(?)'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档指出:


Android O允许您通过在 res / font / 文件夹中添加字体文件
将字体作为资源捆绑。

Android O lets you bundle fonts as resources by adding the font file in the res/font/ folder.

结果:


你可以使用 getFont(int) 方法检索字体,其中
需要传递所需字体的资源标识符到
检索。此方法返回Typeface对象。如果它是字体
系列,则会对字体的第一个重量或样式变体进行
编码。然后,您可以使用Typeface.create(字体,样式)方法
来检索特定样式。

You can retrieve fonts by using the getFont(int) method, where you need to pass the resource identifier of the font that you want to retrieve. This method returns a Typeface object. This encodes the first of the weight or style variants of your font, if it is a font family. You can then use the Typeface.create(typeface, style) method to retrieve specific styles.

注意:TextView已经为您执行此操作。

Note: The TextView already does this for you.

字体字体= getResources()。getFont(R.font.myfont);
textView.setTypeface(字体);

不幸的是,当我使用上面的代码时,我收到以下错误:

Unfortunately when I am using the above code I get the following error:

cannot resolve method 'getFont(?)'

以前我曾经做过以下事情:

Previously I used to do the following:

Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf");

但是现在当我尝试在中创建 fonts 文件夹时资源文件夹,它会自动跳转到 res 文件夹。

But now when I try to create the fonts folder inside assets folder, it automatically jumps inside res folder.

我正在使用 android studio 2.3 。在此先感谢您的帮助。

I am using android studio 2.3. Thanks in advance for any help.

推荐答案

由于我无法直接创建 fonts 文件夹Android Studio,我使用 Windows资源管理器打开项目文件夹,并在 app \src \main \ assets \ 字体 code>文件夹并在那里粘贴我的字体文件。

Since I was not able to create fonts folder directly from Android Studio, I opened the project folder using windows explorer and created the fonts inside app\src\main\assets\ folder and pasted my font file there.

正如许多其他人在答案中建议我必须使用 Android Studio 2.4 Canary 能够使用Android O的新功能。 文档指出:

As so many other guys suggested in the answers I had to use Android Studio 2.4 Canary to be able to use Android O new features. The documentation states:


只有Android Studio 2.4支持Android O提供的所有新开发者
功能。所以你需要获得canary
版本的Android Studio 2.4才能开始使用Android O SDK。但是
您仍然可以安装稳定版本的Android Studio。

Only Android Studio 2.4 includes support for all the new developer features available with Android O. So you need to get the canary version of Android Studio 2.4 to begin using the Android O SDK. But you can still keep your stable version of Android Studio installed.

这篇关于无法解析方法'getFont(?)'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆