【发布时间】:2015-06-14 19:07:10
【问题描述】:
我需要动态设置通知图像图标,其名称动态传递给我的类。 为此,我需要设置 builder.setSmallIcon(int res_id)。我用谷歌搜索了它,但人们使用了 setDrawableImage() 的例子 我看过这篇文章,并在我的代码中相应地实现了。
//blah blah lines of code
String uri = "@drawable/a";
int imageResource = con.getResources().getIdentifier(uri,null, con.getPackageName());
Drawable res = con.getResources().getDrawable(imageResource);
builder.setSmallIcon(res);
//blah blah code lines
当然,这会显示错误,因为 setSmallIcon() 需要将整数传递给它。 con 是传递给我的构造函数的上下文。 我看过How to set the image from drawable dynamically in android?的帖子
【问题讨论】:
标签: android dynamic android-resources