我推薦使用已經看過的SlidingMenu庫,https://github.com/jfeinstein10/SlidingMenu。
這是非常容易設置,並與切換活動,而不是片段效果很好。它與官方導航抽屜不完全相同,但效果相似。我已經在我的應用程序中實現了它(切換活動)。
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidth(8);
menu.setFadeDegree(0.8f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(800);
menu.setMenu(R.layout.menu_frame);
navListView = (ListView) findViewById(R.id.nav_menu);
final String[] nav = { "Item 1",
"Item 2",
"Item 3",
"Item 4",
"Item 5"
};
// A list of type RowItem, which essentially just stores the titles of each item
List<RowItem> rowItems;
rowItems = new ArrayList<RowItem>();
for (int i = 0; i < nav.length; i++) {
RowItem item = new RowItem(navPhoto[i], nav[i]);
rowItems.add(item);
}
// A custom adapter, for laying out the row item in sliding menu
CustomListViewAdapter listAdapter = new CustomListViewAdapter(this,
R.layout.nav_item_layout, rowItems);
navListView.setAdapter(listAdapter);
// You can set this onItemClickListener to listen for click events in the nav list
// And open new activities based on that
navListView.setOnItemClickListener(this);
嗨Rahin,當創建一個活動時,與該活動生成相應的XML佈局文件。我是否需要在新活動的xml文件中複製抽屜佈局,如果我想在應用程序中更深入地進入新活動時保留菜單? – user3018276
如果您計劃在每次點擊導航抽屜碎片時調用新活動的邏輯,那麼是的,您需要複製新活動的抽屜佈局。我推薦做的是遵循@ muslidrikk的建議,並觀看他們關於導航抽屜設計的視頻。 – Rahin