Android:导航抽屉子菜单:如何折叠导航项 [英] Android: Navigation Drawer SubMenu: How to Collapsible navigation items
本文介绍了Android:导航抽屉子菜单:如何折叠导航项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有 10 个选项的导航抽屉选项 #5 应该有另外 7 个选项(如子菜单),可以展开/折叠
如何创建一个可折叠导航项",就像它描述的那样
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?
解决方案
Here is a sample application which makes it:
PrashamTrivedi / DrawerLayoutTest: Link is dead
@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:
这篇关于Android:导航抽屉子菜单:如何折叠导航项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文