You can try using ContextCompat.getDrawable(getActivity(), R.drawable.name);
. This will return a styled Drawable as instructed by your Activity's theme. Your code would be more or less as shown below:
buttonItem.setImageDrawable(ContextCompat.getDrawable(getActivity(), painting.getId()));
NOTE: I'm assuming that painting.getId()
returns the resource id for the image you want to set as your button's drawable. Also, if you are doing this inside an Activity, you should use the keyword this
instead of getActvity()
.