本篇接續:使用 Android Navigation Drawer 製作側選單(1)
前面我們做到從螢幕左邊往右滑來開啟側選單,但是觸碰 ActionBar 的 App icon 時卻沒有任何反應,現在就來處理 App icon 的動作。很簡單,覆寫 onOptionsItemSelected 方法即可:
前面我們做到從螢幕左邊往右滑來開啟側選單,但是觸碰 ActionBar 的 App icon 時卻沒有任何反應,現在就來處理 App icon 的動作。很簡單,覆寫 onOptionsItemSelected 方法即可:
public boolean onOptionsItemSelected(MenuItem item) {
//home
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
這樣當你觸碰 App icon 時就可以開關 drawer 了。