在运行时创建Drawable并添加到资源中 [英] Create Drawable at Runtime and add into Resources

查看:276
本文介绍了在运行时创建Drawable并添加到资源中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行时为Android应用程序创建Drawable.这些Drawables是从字体图标FontAwesome生成的.我正在寻找一种将这些可绘制对象添加到我的Android项目的资源中的方法.我想在应用程序的开头生成可绘制对象,并通过访问资源在其他应用程序中使用它们.

I create Drawable for my Android application at runtime. These Drawables are generated from font icon FontAwesome. I'm searching a way to add these drawables into Resources of my Android project. I would like to generate drawables at start of the application and use them in the rest of the application by accessing through resources.

是否可以使用Java代码将可绘制对象添加到项目资源中?

Is it possible to add a drawable object into project resources in Java code?

推荐答案

您无法在运行时将可绘制对象添加到项目资源中.这些在您创建应用时会编译到您的APK中.您可以做的是在运行时创建可绘制对象,并保持对它的引用,直到您需要在整个应用程序生命周期中重用它(当然,请确保选择此路径不会意外泄漏任何内存)

You can't add a drawable to your project resources at runtime. These are compiled into your APK when you create the app. What you can do is create the drawable at runtime and hold a reference to it for as long as you need it to be reused throughout the application lifecycle (of course, make sure you don't accidentally leak any memory if you choose this route).

这篇关于在运行时创建Drawable并添加到资源中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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