移植SlidingMenu Android library,和安裝example出現的問題解決

來源:互聯網
上載者:User

標籤:android   blog   http   ar   io   os   使用   sp   for   

很多項目都用到類似左側滑動菜單的效果,比如facebook,evernote,VLC for android等等,這很酷

原始碼可以從GitHub的https://github.com/jfeinstein10/slidingmenu上下載。

移植過程中會用到Actionbarsherlock這個項目,去http://actionbarsherlock.com/download.html下載。(兩個下的都是最新版本)

 

步驟:

1.將下載的Actionbarssherlock中/library下的檔案解壓到workspace(你的項目目錄),改項目名稱為Actionbarssherlock,從eclipse中操作new->project->Android Project from Existing Code將項目添加進去,target改為api14以上。

2.將下載的slidingmenu中/library解壓到workspace(你的項目目錄),改名SlidingMenu,import該項目,右鍵->properties->android->api14以上。或者開啟project.properties:target=Google Inc.:Google APIs:14或更高。

3.這樣SlidingMenu就可以用在自己項目中了。讓我們來運行例子。解壓slidingmenu中/example。import該項目,設定api14或更高,並add你的SlidingMenu。運行看看效果。2.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以上.

 

二、修複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這個類並在聲明前添加以下代碼:

       

      [java] view plaincopy 
      1. import com.actionbarsherlock.app.SherlockFragmentActivity;  

       

      然後,將下面這個父類:

       

       

      [java] view plaincopy 
      1. public class SlidingFragmentActivity extends FragmentActivity implements SlidingActivityBase {  

       

      換成Actionbarsherlock裡的另外一個父類:

       

      [java] view plaincopy 
      1. public class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase {  

       

       

      如果錯誤還是會出現,就clean項目並重啟eclipse.

       

      沒錯誤以後運行出下面效果:

    •  

移植SlidingMenu Android library,和安裝example出現的問題解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.