[关闭]
@act262 2017-09-19T04:45:05.000000Z 字数 716 阅读 1014

Android Compat 库

compat


正确使用 support 库

  1. public class ViewCompat {
  2. public static void setBackground(View targetView, Drawable drawable) {
  3. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  4. targetView.setBackground(drawable);
  5. } else {
  6. //noinspection deprecation
  7. targetView.setBackgroundDrawable(drawable);
  8. }
  9. }
  10. }

在Support library 25+以后ViewCompat自带了setBackground方法

  1. ViewCompat.setBackground(mView, background);
  1. public static final ColorStateList getColorStateList(Context context, @ColorRes int id)
  1. public static final Drawable getDrawable(Context context, @DrawableRes int id)
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注