GitHub上最火的開源項目SlidingMenu導入出錯的終極解決方案

SlidingMenu開源項目下載地址https://github.com/jfeinstein10/slidingmenu

Actionbarsherlock開源項目下載地址:http://actionbarsherlock.com/download.html


導入步驟如下:

1.將下載的Actionbarsherlock中/actionbarsherlock文件夾複製到workspace(你的項目工作空間),改名爲Actionbarsherlock,從eclipse中操作new->project->Android Project from Existing Code將項目添加進去,target改爲api14以上。

2.將下載的slidingmenu中/library文件夾複製到workspace(你的項目工作空間),改名SlidingMenu,從eclipse中操作new->project->Android Project from Existing Code將項目添加進去,target改爲Google APIs 14以上。或者打開project.properties:target=Google Inc.:Google APIs:14或更高。

3.這樣SlidingMenu就可以用在自己項目中了。讓我們來運行例子。解壓slidingmenu中/example。從eclipse中操作new->project->Android Project from Existing Code將項目添加進去,target改爲api14以上。運行看看效果。2.1以上的系統都可以運行。


導入之後可能會出現的問題如下:

1、SlidingMenu library project出現錯誤

  • Console error: Unable to resolve target ‘Google Inc.:Google APIs:16.

    Fix: 進入Properties檢查Target sdk是否選擇了 Google APIs.

  • List of errors: 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

    Fix: 將manifest裏面的min sdk version 改爲你當前用到的sdk版本,7

2、SlidingMenu example project出現錯誤

  • Console error: Found 2 versions of android-support-v4.jar in the dependency list,but not all the versions are identical (check is based on SHA-1 only at this time). Jar mismatch! Fix your dependencies

    Fix: 這是由於jar包版本不一致導致的,檢查SlidingMenu和Actionbarsherlock中的\libs文件夾裏的哪個android-support-v4.jar版本比較新,用新的替換掉其中的老版本. 如果錯誤還是會出現,就clean項目並重啓eclipse.

  • List of errors: 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

    Fix:打開SlidingMenu library project裏SlidingFragmentActivity這個類並在聲明前添加以下代碼:

    import com.actionbarsherlock.app.SherlockFragmentActivity; 
    然後,將下面這個父類:

    public class SlidingFragmentActivity extends FragmentActivity implements SlidingActivityBase {
    換成Actionbarsherlock裏的另外一個父類(如果此時Library沒有引用Actionbarsherlock庫項目,則先引用之):

    public class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase { 

    附上運行效果圖之一:



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章