在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以上。




Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐