动态创建可绘制资源路径

时间:2010-09-06 13:35:26

标签: android

我有以下代码行:

Notification notif = new Notification(R.drawable.notification_XX, "Notify", System.currentTimeMillis());

我的问题是我希望R.drawable.notification_XX可以更改,例如,如果我有变量i = 24;,则应使用相应的资源R.drawable.notification_24

那么,有没有办法动态创建可绘制的资源路径?

提前感谢,马丁

1 个答案:

答案 0 :(得分:5)

如果您想更改通知以显示一个号码,您只需设置the number field of your Notification object,相应的号码就会覆盖在通知栏中的图标上。

但是,如果您确实有许多不同的图标,则可以使用getIdentifier() method on Resources来返回给定名称的资源ID。