{"id":3972,"date":"2014-03-30T06:45:14","date_gmt":"2014-03-30T06:45:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-get-android-resource-id-from-dynamically-created-in-java-layer-list-layerdrawable-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:45:14","modified_gmt":"2014-03-30T06:45:14","slug":"how-to-get-android-resource-id-from-dynamically-created-in-java-layer-list-layerdrawable-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-get-android-resource-id-from-dynamically-created-in-java-layer-list-layerdrawable-collection-of-common-programming-errors\/","title":{"rendered":"How to get Android resource ID from dynamically-created (in Java) layer-list \/ LayerDrawable?-Collection of common programming errors"},"content":{"rendered":"<p>The &#8220;solution #2 (dynamic)&#8221; in this question\/answer post:<\/p>\n<p>overlay two images in android to set an imageview<\/p>\n<p>is very close to what I want to do, which is to dynamically create a layer-list (for a status bar notification icon, I want to build-up my icon in layers), but the icon assignment in the notification API requires a resource ID (which I want to call from a service).<\/p>\n<p>I cannot figure-out how to build a dynamically build a layer-list without building hundreds of layer-list .xml files (for the various combinations of icons that I would like to be able to display). Daniel&#8217;s &#8220;solution #1&#8221; works wonderfully for the static .xml files, but I&#8217;m looking for a more elegant, dynamic solution.<\/p>\n<p>In the above post, the code snippet:<\/p>\n<pre><code>  Resources r = getResources();\n\n  Drawable[] layers = new Drawable[2]; \n\n  layers[0] = r.getDrawable(R.drawable.t);\n\n  layers[1] = r.getDrawable(R.drawable.tt);\n\n  LayerDrawable layerDrawable = new LayerDrawable(layers);\n<\/code><\/pre>\n<p>appears to be what I want, but I don&#8217;t know or understand how to &#8220;assign&#8221; the new layerDrawable to my notification icon (which takes a resource ID).<\/p>\n<p>Thanks to all&#8230;stackoverflow is a wonderful resource!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The &#8220;solution #2 (dynamic)&#8221; in this question\/answer post: overlay two images in android to set an imageview is very close to what I want to do, which is to dynamically create a layer-list (for a status bar notification icon, I want to build-up my icon in layers), but the icon assignment in the notification API [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3972","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3972"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3972\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}