下载到SlideMenu的源码,打开例子,发现有些错误,先把依赖的包给导入
发现在BaseActivity有几个红叉,提示不能使用getActionBar...什么的
分析一下其使用过程,
首先 BaseActivity extends SlidingFragmentActivity
为了兼容性,SlidingFragmentActivity继承的FragmentActivity 来适应旧的平台,但是还是有些问题, 所以SlidingFragmentActivity 继承SherlockFragmentActivity
使用SlideMenu用Fragment来填充内容,所有得有个容器来放置菜单栏
layout.menu_frame.xml
layout.menu_frame_two.xml
BaseActivity :设置第一个侧滑菜单
setBehindContentView(R.layout.menu_frame);
1 // set the Behind View 2 setBehindContentView(R.layout.menu_frame); 3 if (savedInstanceState == null) { 4 FragmentTransaction t = this.getSupportFragmentManager().beginTransaction(); 5 mFrag = new SampleListFragment(); 6 t.replace(R.id.menu_frame, mFrag); 7 t.commit(); 8 } else { 9 mFrag = (ListFragment)this.getSupportFragmentManager().findFragmentById(R.id.menu_frame); 10 }
对slidemenu定义控制属性
SlidingMenu sm = getSlidingMenu(); //
sm.setBehindOffsetRes(); //设置滑动后距离另一边的距离,使用资源文件
sm.setBehindOffset(); //直接使用数字
sm.setFadeDegree(); //设置淡入淡出效果
sm.setShadow...//阴影效果
1 // customize the SlidingMenu 2 SlidingMenu sm = getSlidingMenu(); 3 sm.setShadowWidthRes(R.dimen.shadow_width); 4 sm.setShadowDrawable(R.drawable.shadow); 5 sm.setBehindOffsetRes(R.dimen.slidingmenu_offset); 6 sm.setFadeDegree(0.35f); 7 sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); 8 9 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
PropertiesActivity extends BaseActivity
sm.setMode() //设置滑动的模式:从左边滑动,右边滑动,左右两边都可以滑动
sm.setSecondaryMenu(R.layout.menu_frame_two);//设置右边第二个滑动菜单
1 SlidingMenu sm = getSlidingMenu(); 2 switch (checkedId) { 3 case R.id.left: 4 sm.setMode(SlidingMenu.LEFT); 5 sm.setShadowDrawable(R.drawable.shadow); 6 break; 7 case R.id.right: 8 sm.setMode(SlidingMenu.RIGHT); 9 sm.setShadowDrawable(R.drawable.shadowright); 10 break; 11 case R.id.left_right: 12 sm.setMode(SlidingMenu.LEFT_RIGHT); 13 sm.setSecondaryMenu(R.layout.menu_frame_two); 14 getSupportFragmentManager() 15 .beginTransaction() 16 .replace(R.id.menu_frame_two, 17 new SampleListFragment()).commit(); 18 sm.setSecondaryShadowDrawable(R.drawable.shadowright); 19 sm.setShadowDrawable(R.drawable.shadow); 20 } 21
setTouchModeAbove(); 设置滑动模式:全屏手势,边框滑动,无
1 case R.id.touch_above_full: 2 getSlidingMenu().setTouchModeAbove( 3 SlidingMenu.TOUCHMODE_FULLSCREEN); 4 break; 5 case R.id.touch_above_margin: 6 getSlidingMenu().setTouchModeAbove( 7 SlidingMenu.TOUCHMODE_MARGIN); 8 break; 9 case R.id.touch_above_none: 10 getSlidingMenu().setTouchModeAbove( 11 SlidingMenu.TOUCHMODE_NONE); 12 break;