Create drawable resource path dynamically
I have something like the following line of code:
Notification notif = new Notification(R.drawable.notification_XX, "Notify", System.currentTimeMillis());
My problem is that i want to make R.drawable.notification_XX
changeable, so for example if I have a variable i = 24;
then the appropriate resource R.drawable.notification_24
should be used
So, is th开发者_运维问答ere a way of creating a drawable resource path dynamically?
thanks in advance, Martin
If you want to change the Notification to display a number you can just set the number
field of your Notification
object and the appropriate number will be overlaid over your icon in the Notifications bar.
However, if you really have a number of different icons you can use the getIdentifier()
method on Resources
which will return the Resource ID for a given name.
精彩评论