drawer的用法_MaterialDrawer使用指南

1.添加依赖

compile(‘com.mikepenz:materialdrawer:5.1.6@aar’) {

transitive = true

}

2.直接在代码中新建

private Drawer mainDrawer = null;

private void initSlidingDrawer(Bundle savedInstanceState) {

// Handle Toolbar

mainDrawer = new DrawerBuilder()

.withActivity(this)

//跟drawerlayout用法相同,用这个drawer替换覆盖掉原来drawerlayout的位置

.withRootView(R.id.drawer_container)

.withHeader(R.layout.view_drawer_header)

.withHeaderDivider(false)

.withSavedInstance(savedInstanceState)

//与toolbar关联起来

.withToolbar(mToolbar)

//启用toolbar的ActionBarDrawerToggle动画

.withActionBarDrawerToggleAnimated(true)

.withDisplayBelowStatusBar(false)

.withTranslucentStatusBar(false)

.withDrawerLayout(R.layout.material_drawer)

.addDrawerItems(

new PrimaryDrawerItem().withName("需求信息").withIcon(R.mipmap.ic_assignment_turned_in_black_48dp).withIdentifier(1),

new PrimaryDrawerItem().withName("我的商品").withIcon(R.mipmap.ic_local_grocery_store_black_48dp).withIdentifier(2),

new PrimaryDrawerItem().withName("我的消息").withIcon(R.mipmap.ic_chat_bubble_outline_black_48dp).withIdentifier(3),

new PrimaryDrawerItem().withName("设置").withIcon(R.mipmap.ic_build_black_48dp).withIdentifier(4)

)

.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

@Override

public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {

if (drawerItem != null) {

switch (drawerItem.getIdentifier()) {

case 1:

setToolBarTitle("需求信息");

fragUtils.showFragment(Tag_DemandProductListFrag);

break;

case 2:

setToolBarTitle("我的商品");

fragUtils.showFragment(Tag_SupplyProductListFrag);

break;

case 3:

setToolBarTitle("我的消息");

fragUtils.showFragment(Tag_MyMessageListFrag);

break;

case 4:

setToolBarTitle("设置");

fragUtils.showFragment(Tag_SettingFrag);

break;

default:

break;

}

}

return false;

}

}).build();

}

@Override

protected void onSaveInstanceState(Bundle outState) {

outState = mainDrawer.saveInstanceState(outState);

super.onSaveInstanceState(outState);

}

3.在color.xml、dimen.xml和style.xml中对MaterialDrawer的各个元素进行自定义设置

@color/md_white_1000

@color/md_grey_800

@color/md_grey_800

@color/material_drawer_dark_hint_text

@color/md_grey_600

@color/abl_blue

@color/md_white_1000

@color/material_drawer_dark_primary_text

4.dimen 中的一些配置

18sp

240dp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值