在机器人工作室资产文件夹? [英] Assets folder in Android Studio?

查看:104
本文介绍了在机器人工作室资产文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着使用自定义的字体,我读过,我想,把资产/字体的字体。我使用的是Android的工作室,它似乎并没有像我有一个资产文件夹。所以,我创建了一个。但我的应用程序崩溃时,我将资产文件夹在src / main。即时通讯使用这种code加载我的字体。

Im trying to use a custom font, and I've read that I suppose to place the fonts in assets/fonts. I'm using Android Studio and it doesn't seem like I have a assets folder. So I created one. But my app crashes when I place the assets folder in src/main. Im using this code to load my fonts.

Typeface fontRegular = Typeface.createFromAsset(getAssets(), "fonts/DroidSans.ttf");
Typeface fontBold = Typeface.createFromAsset(getAssets(), "fonts/DroidSans-Bold.ttf");

myDeviceModelTxt.setTypeface(fontRegular);

我是什么做错了吗?

What am I doing wrong?

推荐答案

我不知道是否有任何的bug修复,因为这被问过,但我是用当前的结构在Android的工作室0.5.2项目:

I am not sure if there has been any bug fixes since this was asked, but I am using the current structure for a project in Android Studio 0.5.2:

root-module
|--.idea
|--app
|----build
|----src
|------main
|--------assets
|----------SomeFont.ttc
|----------AnotherFont.otf
|--------java
|----------source code here
|--------res
|------AndroidManifest.xml
|----build.gradle

和调用然后获取它

Typeface.createFromAsset(mContext.getResources().getAssets(), "SomeFont.ttc");

谨慎

字虽然有一个错误(<一href="https://$c$c.google.com/p/android/issues/detail?id=9904">https://$c$c.google.com/p/android/issues/detail?id=9904)是$ P $被当作垃圾妥善收集pvents字体。使用单!

Word of caution though, there is a bug (https://code.google.com/p/android/issues/detail?id=9904) that prevents typefaces from being garbage collected properly. Use a singleton!

这篇关于在机器人工作室资产文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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