天天看點

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

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

步驟:

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這個類并在聲明前添加以下代碼:

import com.actionbarsherlock.app.SherlockFragmentActivity;  

然後,将下面這個父類:

public class SlidingFragmentActivity extends FragmentActivity implements SlidingActivityBase {  

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

public class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase {  

如果錯誤還是會出現,就clean項目并重新開機eclipse.

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

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

繼續閱讀