Android: Navigation Drawer SubMenu: How to Collapsible navigation items

眉间皱痕 提交于 2019-12-18 10:36:06

问题


I have a Navigation Drawer with 10 options Option #5 shoudl have another 7 options (like a sub menu) of some sort that is expandable/collapsible

How do I create a "Collapsible navigation items" like it is described here?


回答1:


Here is a sample application which makes it:

PrashamTrivedi / DrawerLayoutTest: Link is dead

EDIT: Simple Navigational Drawer Layout in Android

@Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
    {
        if (convertView == null)
        {
            LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.drawer_group_item,parent,false);
        }

        ((TextView) convertView).setText(groupItem.get(groupPosition));
        convertView.setTag(groupItem.get(groupPosition));
        return convertView;
    }

@Override
    public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
    {
        tempChild = (ArrayList<String>) children.get(groupPosition);
        TextView text = null;

        if (convertView == null)
        {
            LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.drawer_submenu_item,parent,false);
        }

        text = (TextView) convertView;
        text.setText(tempChild.get(childPosition));

        convertView.setTag(tempChild.get(childPosition));
        return convertView;
}

And you have to create the new xml files in the layout folder (hint: create two, one for the group view and other for the submenu)

After all your side navigation must look like as below:



来源:https://stackoverflow.com/questions/17149776/android-navigation-drawer-submenu-how-to-collapsible-navigation-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!