Git開源專案SlidingMenu移植問題

傲慢的上校發表於2013-06-07

        在Csdn上,看到介紹的開源專案http://www.csdn.net/article/2013-05-03/2815127-Android-open-source-projects,中的第三個專案:SlidingMenu,很多App都加了這種選單形式,所以也想研究一下。

        其專案Git地址:https://github.com/jfeinstein10/slidingmenu

           把專案同步到本地以後,使用Eclipse匯入,發現會出錯,開啟專案的Properties選項:


發現其所依賴的ABS庫出錯,ABS究竟是什麼呢?

        原來專案中還依賴Actionbarsherlock這個庫,可以在http://actionbarsherlock.com/download.html獲取,匯入到eclipse裡,我命名比較懶,直接命名為library2,

匯入library2之前:

匯入後出現以下情況:


      錯誤變成了缺少android-support-v4包支援。

      後來發現是因為,library類庫中和Actionbarsherlock庫中都依賴android-support-v4庫,可能是因為版本不一,引發衝突,把Actionbarsherlock原始碼中libs中android-support-v4刪除,然後拷貝library中的android-support-v4到Actionbarsherlock中即可。

      這個時候發現,可能還有以下錯誤:

The method getSupportActionBar() is undefined for the type BaseActivity
The method getSupportMenuInflater() is undefined for the type BaseActivity
The method onCreateOptionsMenu(Menu) of type BaseActivity must override or implement a supertype method
The method onOptionsItemSelected(MenuItem) in the type Activity is not applicable for the arguments
The method onOptionsItemSelected(MenuItem) of type BaseActivity must override or implement a supertype method
The method onOptionsItemSelected(MenuItem) of type ResponsiveUIActivity must override or implement a supertype method

    修改方法為:開啟SlidingMenu library project裡SlidingFragmentActivity這個類並在宣告前新增以下程式碼:

import com.actionbarsherlock.app.SherlockFragmentActivity; 

    

然後,將下面FragmentActivity父類:

public class SlidingFragmentActivity extends FragmentActivity implements SlidingActivityBase {  

替換為:Actionbarsherlock庫裡的另外一個父類:

public class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase {  

這裡SlidingMenu library需要依賴Actionbarsherlock,加上即可,如果還有錯誤,clean下。


PS:

     有可能遇到以下錯誤:

ACTION_POINTER_INDEX_MASK cannot be resolved android.
HONEYCOMB cannot be resolved or is not a field
LAYER_TYPE_HARDWARE cannot be resolved or is not a field
LAYER_TYPE_NONE cannot be resolved or is not a field
MATCH_PARENT cannot be resolved or is not a field
The method getLayerType() is undefined for the type View
The method setLayerType(int, null) is undefined for the type View

     修改方法: manifest裡面的min sdk version 改為你當前用到的sdk版本7以上。




相關文章