android support的作用及其常見錯誤的解決,androidsupport
首先我們要明白這些包到底是幹什麼用的
google提供了Android Support Library package 系列的包來保證來高版本sdk開發的向下相容性,即我們用4.x開發時,在1.6等版本上,可以使用高版本的有些特性,如fragement,ViewPager等,下面,簡單說明下這幾個版本間的區別:
- Android Support v4: 這個包是為了照顧1.6及更高版本而設計的,這個包是使用最廣泛的,eclipse建立工程時,都預設帶有了
- Android Support v7: 這個包是為了考慮照顧2.1及以上版本而設計的,但不包含更低,故如果不考慮1.6,我們可以採用再加上這個包,另外注意,v7是要依賴v4這個包的,即,兩個得同時被包含
- Android Support v13 :這個包的設計是為了android 3.2及更高版本的,一般我們都不常用,平板開發中能用到。
匯入這些包遇見的各種各樣的問題
- 項目中需要使用到Android support包中提供的東西,不免就要把support包放到libs下,然後使用。但我在使用android-support-v7-appcompat.jar卻出現了如下問題:
- 我明明使用了v7的包,ActionBarActivity類也匯入成功了,但還是用不了~~
- 原來v7是對v4存在依賴的,並且兩者的版本還必須一樣,否則沒法使用。所以只需要在網上找個v4和v7一起的資源放在一起用就行了。
- Android sdk裡面都內建的有這些support包,位置為..\sdk\extras\android\support。如果想用v7的包,直接到..\sdk\extras\android\support\v7\appcompat\libs下拿就行了,其他類同。不僅版本一致,而且版本都是與當前sdk的版本一致的
可能遇到的問題一: styles......No resource found
res\values\styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.對於values這個地方產生的no resource found問題,說明是沒有v7下的資源
可能遇到的問題二:values-v11,values-v21,values-v17等等下的No resource found
appcompat\res\values-v21\styles_base.xml:75: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'.appcompat\res\values-v11\themes_base.xml:178: error: Error: No resource found that matches the given name: attr 'android:windowActionBar'.appcompat\res\values-v14\themes_base.xml:27: error: Error: No resource found that matches the given name: attr 'android:actionModePasteDrawable'.對於在values-v11這類針對不同android target載入的values下找不到資源的問題,原因還是一樣,找不到這個target下的資源