开发者

Create drawable resource path dynamically

开发者 https://www.devze.com 2023-01-14 19:57 出处:网络
I have something like the following line of code: Notification notif = new Notification(R.drawable.notification_XX, \"Notify\", System.currentTimeMillis());

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消