在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 {
public class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase {
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以上。