@act262
2017-09-19T04:45:05.000000Z
字数 716
阅读 1260
compat
正确使用 support 库
minSdk<16 时必须用setBackgroundDrawable设置背景,
public class ViewCompat {public static void setBackground(View targetView, Drawable drawable) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {targetView.setBackground(drawable);} else {//noinspection deprecationtargetView.setBackgroundDrawable(drawable);}}}
在Support library 25+以后ViewCompat自带了setBackground方法
ViewCompat.setBackground(mView, background);
ContextCompat#getColorStateList替换
public static final ColorStateList getColorStateList(Context context, @ColorRes int id)
Contextpat#getDrawable替换
public static final Drawable getDrawable(Context context, @DrawableRes int id)
