开源地址:https://github.com/SimonVT/android-menudrawer
简介:menudrawer是跟sliderMenu差不多的一种框架,常被应用做设置界面,以menu作为设置菜单,contentView作为详细页面的框架,如下图
API详解:
****************************左边MenuDrawer***************************************
1.设置主页
menuDrawer=MenuDrawer.attach(this,MenuDrawer.MENU_DRAG_CONTENT);
menuDrawer.setContentView(R.layout.activity_main);
2.设置Menu页/高度
menuDrawer.setMenuView(mListView);
menuDrawer.setMenuSize(getWindowManager().getDefaultDisplay().getWidth());
3.主/Menu页相互跳转
menuDrawer.toggleMenu();
4.关闭Menu页
menuDrawer.closeMenu();
5.右边标示的保存和滑动:
getView(设置Tag): v.setTag(R.id.mdActiveViewPosition, position);
OnItemClickListener(设置当前活跃Item):menuDrawer.setActiveView(v,position);
6.滑动时(刷新指示标示)
mListView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
menuDrawer.invalidate();
}
});
7.设置拖动有效的区域
menuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
8.第4个参数判断能否被拖动
menuDrawer=MenuDrawer.attach(this,MenuDrawer.MENU_DRAG_CONTENT,Position.RIGHT,true);
****************************右/上下边MenuDrawer***************************************
1.设置主页(第3个参数提供了菜单的4个方向)
menuDrawer=MenuDrawer.attach(this,MenuDrawer.MENU_DRAG_CONTENT, Position.RIGHT);
2.修改指示器的位置:
1)在AndroidManifest.xml中修改样式
android:theme="@style/SampleTheme.Right"
2)在theme.xml中修改:
<style name="SampleBase" parent="@android:style/Theme.Holo.Light" />
<style name="SampleTheme.Right" parent="SampleBase">
<item name="menuDrawerStyle">@style/MenuDrawerStyle.Right</item>
</style>
3)在style.xml中修改:
<style name="MenuDrawerStyle.Right" parent="Widget.MenuDrawer">
<item name="mdActiveIndicator">@drawable/menu_arrow_right</item>
<item name="mdMenuSize">200dp</item>
</style>
****************************自定义MenuDrawer***************************************
XML:
View层必须是net.simonvt.menudrawer.TopDrawer四种中的一种定义
menu页的id必须为android:id="@id/mdMenu"
主页的id必须是android:id="@id/mdContent"
代码:设置手动模式并设置menu宽/高
menuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
menuDrawer.setMenuSize(50);
定义指示位置:(指示标的显示得由manifest文件里面的theme指定)menuDrawer.setActiveView(v);
****************************MenuDrawer+ViewPager***************************************
Tip:1)主页实现FragmentActivity;
2)在onPageChangeListener中onPageSelected实现:
menuDrawer.setTouchMode(position==0?MenuDrawer.TOUCH_MODE_FULLSCREEN:MenuDrawer.TOUCH_MODE_NONE);