MaterialDrawer 사용 설명서

4260 단어
https://github.com/mikepenz/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과 스타일.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

좋은 웹페이지 즐겨찾기