Navigation Drawer - Divider between sections like Gmail App

后端 未结 3 1278
轮回少年
轮回少年 2021-01-07 08:14

I am updating the Navigation Drawer in my app. I want to add section dividers as the Gmail App has. How do I add them? Just add them as views, which is a simple approach. Bu

3条回答
  •  粉色の甜心
    2021-01-07 09:07

    I used headerview and footerview to add the image on top and divider at the bottom. The divider is a View.

    drawer_list_footer_divider.xml

    
    
    
        
    
    
    

    drawer_list_footer_view.xml

    
    
    
        
    
        
    
    
    

    and in my code:

    private void setUpHeaderAndFooter() {
    
        LayoutInflater inflater = getLayoutInflater();
        View header = (View) inflater.inflate(R.layout.drawer_list_header_view,
                mDrawerList, false);
        mDrawerList.addHeaderView(header, null, false);
    
        View footer_divider = (View) inflater.inflate(
                R.layout.drawer_list_footer_divider, null, false);
        mDrawerList.addFooterView(footer_divider, null, false);
    
        // This view is Settings view 
        View footer = (View) inflater.inflate(R.layout.drawer_list_footer_view,
                mDrawerList, false);
    
        footer.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
    
                if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
                    mDrawerLayout.closeDrawer(Gravity.LEFT);
                }
    
                if (android.os.Build.VERSION.SDK_INT < 11) {
                    startActivity(new Intent(MainActivity.this,
                            Settings1Activity.class)
                            .setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
                } else {
                    startActivity(new Intent(MainActivity.this,
                            Settings2Activity.class)
                            .setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
                }
    
            }
        });
    
        mDrawerList.addFooterView(footer, null, true);
    
    }
    

提交回复
热议问题