Android 版本兼容 向下兼容
1.6、2.1還是佔有一定的市場,故在有些時候,我們還是得要考慮兼容這些版本。
google提供了Android Support Library package 系列的包來保證來高版本sdk開發的向下兼容性,即我們用4.x開發時,在1.6等版本上,可以使用高版本的有些特性,如fragement,ViewPager等,下面,簡單說明下這幾個版本間的區別:
Android Support v4 ( 1.6 ):
這個包是爲了照顧1.6及更高版本而設計的,這個包是使用最廣泛的,eclipse新建工程時,都默認帶有了。
Android Support v7 ( 2.1 ):
這個包是爲了考慮照顧2.1及以上版本而設計的,但不包含更低,故如果不考慮1.6,我們可以採用再加上這個包,另外注意,v7是要依賴v4這個包的,即,兩個得同時被包含。
Android Support v13 (3.2) :
這個包的設計是爲了android 3.2及更高版本的,一般我們都不常用,平板開發中能用到。
向下兼容(Downward Compatible)
又稱向後兼容(Backwards compatibility),計算機術語。向下兼容常常是相對於向上兼容而言的,兩者在兼容的方向性上是相反的,因此這兩個概念是不同的。
suppport jar 位於 sdk/extras/android/support
Support Libraries for Android.
This SDK component contains static libraries providing access to newer APIs
on older platforms and various helper classes.
To use those libraries, simply copy them as static libraries into your project.
Each library is called v<api>, indicating the minimum API level that they require.
*** V4 ***
v4/android-support-v4.jar contains:
- Fragment API. New in API 11 (3.0 - Honeycomb). http://developer.android.com/reference/android/app/Fragment.html
- Loader API. New in API 11 (3.0 - Honeycomb). http://developer.android.com/reference/android/app/LoaderManager.html
- CursorAdapter / ResourceCursorAdapter / SimpleCursorAdapter. These are the API 11 versions.
- MenuCompat allows calling MenuItem.setShowAsAction which only exists on API 11.
v4/src/ is the source code for the compatibility library
v4/samples/ provides a sample app using the library.
*** V13 ***
v13/android-support-v13.jar provides the same features as v4, plus:
- FragmentPagerAdapter: Implementation of PagerAdapter that represents each page as a Fragment.
v13/src/ is the source code for the compatibility library, not including the v4 source
v13/samples/ provides a sample app using the library.