Android getDrawable()和getColor()

Android getDrawable()

1. Obsolete code

Outdated, but not in the way of usability

context.getResources().getDrawable(R.drawable.xxx)

2. Suggest code

context.getDrawable(R.drawable.xxx)

There are API restrictions

3. Latest code

ContextCompat.getDrawable(getContext(), R.drawable.xxx);

There are API restrictions

4. Latest

Drawable drawable= AppCompatResources.getDrawable(context,R.drawable.xxx);

5.getColor()

getColor() is the same as getDrawable()

6. Other

Using getColor() and getDrawable() directly will allow us to choose the imported method

Guess you like

Origin blog.csdn.net/fromVillageCoolBoy/article/details/132006837