2015-10-20 345 views
0

我有一個活動在我的應用程序不是啓動器。 我想添加一個帶有切換器的導航抽屜。我嘗試按照這裏的說明http://developer.android.com/training/implementing-navigation/nav-drawer.html#ActionBarIcon添加導航抽屜通過替換在導航欄中的導航欄

但是我的後退導航仍然顯示(它退出應用程序,因爲我已向該意圖添加了適當的標誌) 如何顯示抽屜開關圖標?

此外android.support.v4.app.ActionBarDrawerToggler已棄用,應該使用什麼?

+0

你想要菜單圖標而不是右後? – Pavan

+0

我想用打開抽屜的圖標替換背部圖標。 – Ishan

回答

0

爲android.support.v4.app.ActionBarDrawerToggler不贊成使用新獲得支持庫supporv7 appcompact這裏檢查https://developer.android.com/intl/es/reference/android/support/v4/app/ActionBarDrawerToggle.html

,創造抽屜式導航在這裏你得到的所有信息 http://developer.android.com/intl/es/training/implementing-navigation/nav-drawer.html

代碼示例

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
     drawer.setDrawerListener(toggle); 
     toggle.syncState(); 

使用最新的支持庫,您將輕鬆完成,而不是使用setHomeasUpEnabled(true)

+0

它說我必須用ToolBar替換ActionBar。在https://developer.android.com/intl/es/reference/android/support/v7/app/AppCompatActivity.html#setSupportActionBar(android.support.v7.widget.Toolbar)中,所需的參數是https:// developer.android.com/intl/es/reference/android/support/v7/widget/Toolbar.html有沒有用於導航抽屜的標準工具欄,還是必須從頭開始創建一個? – Ishan

+0

您可以製作簡單的工具欄並將其設置爲操作欄運行時。 工具欄工具欄=(工具欄)findViewById(R.id.toolbar); setSupportActionBar(toolbar);它將像普通的操作欄一樣工作 – Pavan