How to create Drawable from resource

前端 未结 8 1604
臣服心动
臣服心动 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:26

    If you are inheriting from a fragment you can do:

    Drawable drawable = getActivity().getDrawable(R.drawable.icon)

提交回复
热议问题