Android:导航抽屉SubMenu:如何折叠导航项目

Eri*_*man 18 navigation android drawer

我有一个带有10个选项的导航抽屉选项#5 shoudl有另外7个可扩展/可折叠的选项(如子菜单)

如何创建一个"可折叠的导航项目"就像是描述在这里

cag*_*cak 16

这是一个示例应用程序,它使:

PrashamTrivedi/DrawerLayoutTest

@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;
    }
Run Code Online (Sandbox Code Playgroud)
@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;
}
Run Code Online (Sandbox Code Playgroud)

并且您必须在布局文件夹中创建新的xml文件(提示:创建两个,一个用于组视图,另一个用于子菜单)

所有侧面导航必须如下所示:

抽屉子菜单视图的快照

编辑:Android中简单的导航抽屉布局