2016-12-18 76 views
-2

This is a picture of navigation drawer.從導航抽屜

This is the picture of main activity

切換標籤我有一個導航抽屜,並且在主要活動我有3個突出部。我想在導航抽屜點擊標籤之間切換。 像我現在在服務選項卡。但是,當我點擊導航抽屜活動中的主頁時,我想看到「主頁」選項卡。

+1

開始請提供一些代碼和上下文 –

+0

爲什麼你會擁有相同的元素標籤和抽屜式導航?只需使用一種導航模式 –

+0

客戶端,我必須這樣做。 –

回答

0

正確的代碼語法是 viewPager.setCurrentItem(0)爲主頁選項卡。 viewPager.setCurrentItem(1)服務選項卡。 viewPager.setCurrentItem(2)有關我們標籤

標籤索引從0

public boolean onNavigationItemSelected(MenuItem item) 
    { 
     // Handle navigation view item clicks here. 
     int id = item.getItemId(); 

     if (id == R.id.nav_home) 
     { 
      viewPager.setCurrentItem(0); 
     } 
     else if (id == R.id.nav_aboutus) 
     { 
      viewPager.setCurrentItem(2); 
     } 
}