How to create Drawable from resource

前端 未结 8 1603
臣服心动
臣服心动 2020-12-04 07:48

I have an image res/drawable/test.png (R.drawable.test).
I want to pass this image to a function which accepts Drawable, e.g. mButton.set

8条回答
  •  无人及你
    2020-12-04 08:31

    Your Activity should have the method getResources. Do:

    Drawable myIcon = getResources().getDrawable( R.drawable.icon );
    

提交回复
热议问题