跳至主要内容

博文

目前显示的是标签为“Compat”的博文

[Skill]Android版本兼容器

Android版本兼容器 随着Android版本一代代发布,碎片化的问题越来越严重,不过好在趋势上市面上的版本已经开始比较集中了。但我们终究还是要面对版本兼容问题。我们不能因为要用高版本方法而提高最低版本限制,高版本里炫酷的效果及高效的方法只会导致你的最低版本显示越来越高,而官方的解决方案(Support-v4)无疑是给了我们新的启示。 示例 首先我们抽取一个官方的版本兼容器的一部分看看: /** * Helper for accessing features in {@link TextView} introduced after API level * 4 in a backwards compatible fashion. */ public final class TextViewCompat { // Hide constructor private TextViewCompat () {} interface TextViewCompatImpl { ... int getMaxLines ( TextView textView ); int getMinLines ( TextView textView ); void setTextAppearance ( @NonNull TextView textView , @StyleRes int resId ); Drawable [] getCompoundDrawablesRelative ( @NonNull TextView textView ); } static class BaseTextViewCompatImpl implements TextViewCompatImpl { ... @Override public int getMaxLines ( TextView textView ) { return TextViewCompatGingerbread . getMaxLines(textVi...