随着新的 Android API22 getResources().getDrawable()现已弃用.
A) drawables without theme attributes
ResourcesCompat.getDrawable(getResources(), R.drawable.name, null);
You'll get your unstyled drawable the old way. This is probably what you need.
Please note: ResourcesCompat.getDrawable()
is not deprecated!
B) drawables with theme attributes
ContextCompat.getDrawable(getActivity(), R.drawable.name);
You'll obtain a styled Drawable as your Activity theme instructs.
EXTRA) drawables with theme attributes from another theme
ResourcesCompat.getDrawable(getResources(), R.drawable.name, anotherTheme);