android - 如何从 android 包中的资源 id 获取 Drawable 对象?

标签 android resources drawable android-context

我需要一个 Drawable 对象以显示在图像按钮上。有没有办法使用下面的代码(或类似的代码)从 android.R.drawable.* 包中获取对象?

例如,如果 drawableId 是 android.R.drawable.ic_delete

mContext.getResources().getDrawable(drawableId)

最佳答案

Drawable d = getResources().getDrawable(android.R.drawable.ic_dialog_email);
ImageView image = (ImageView)findViewById(R.id.image);
image.setImageDrawable(d);

关于android - 如何从 android 包中的资源 id 获取 Drawable 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7815689/

相关文章:

Android 将……替换为……

android - 在 web View 中将可绘制资源作为图像访问

android - 在 Android 4.2 的 StateListDrawable 中使用默认的 ShapeDrawable

android - 我的应用程序支持多屏幕吗?

android - Cardboard的YouTube视频流(统一)

android - 在 JSON 对象内将请求作为 JSON 参数发送

c++ - 如何使用 Visual Studio 在 Windows 应用程序中设置图标

java - java中属性文件的路径

android - 这样的线怎么画?

java - 使用改造库更新 GPS 位置并将坐标发送到服务器(在后台服务中)