MaterialDrawerAndroid 侧滑显示控件
MaterialDrawer 是一个类似 Google 官方 NavigationView 侧滑显示控件, 个人认为 NavigationView 并没有 MaterialDrawer 实用, 因为 NavigationView 自由度不是很好, 很多都写死了不可以自由定义布局, 而 MaterialDrawer 能够实现跟 NavigationView 一样的效果, 同时还支持自定义效果, 自由度非常高。
效果图:
使用示例
//if you want to update the items at a later time it is recommended to keep it in a variablePrimaryDrawerItem item1 = new PrimaryDrawerItem().withName(R.string.drawer_item_home);SecondaryDrawerItem item2 = new SecondaryDrawerItem().withName(R.string.drawer_item_settings);//create the drawer and remember the `Drawer` result objectDrawer result = new DrawerBuilder() .withActivity(this) .withToolbar(toolbar) .addDrawerItems( item1, new DividerDrawerItem(), item2, new SecondaryDrawerItem().withName(R.string.drawer_item_settings) ) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { // do something with the clicked item :D } }) .build();
评论