Drawing the Drawable of icon of an app doesn't works

I'm creating a launcher app on Android, and I get the icon of an app by calling mResolveInfo.activityInfo.loadIcon(mPackageManager). The problem is that when I'm trying to draw this drawable on canvas in draw method of my custom view by calling icon.draw(canvas) (where "icon" is the drawable), this draws nothing.

BUT if I set the drawable as the background of the view, it draws the icon pirfectly when I call super.draw(canvas) method.

I don't know what the View class does with the drawables to make them work, but it proves that there must be a way to do this, and I absolutely need to avoid using of super.draw(canvas) method, because I need to customise what my view is drawing when it's focused (if I use my app with a keyboard, for example).

Edit: if my question helped you, please vote it, I have not enough reputation because of stupid questions I have posted in the past so I'm not able to ask a new question no more


  • Okey, finally I found a solution by myself, before somebody was able to answer my question.

    The problem is that the bounds of the drawable were null(all zero), so I just had to call icon.setBounds(0,0, width,height)(where "icon" is the drawable) and now it draws correctly.

    And this is one of things that the setBackground(drawable) method of my view doing with any drawable that I give it. Hope it helps somebody who had the same problem.