So my sdk goes from 15 to 21 and when I call setBackgroundDrawable()
, Android Studio tells me that it\'s deprecated.
I thought of going around it using:
I'm using a minSdkVersion 16 and targetSdkVersion 23 The following is working for me, it uses ContextCompat.getDrawable(context, R.drawable.drawable);
Instead of using: layout.setBackground(getResources().getDrawable(R.drawable.img_wstat_tstorm));
Rather use:
layout.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.img_wstat_tstorm));
getActivity()
is used in a fragment, if calling from a activity use this