2016-12-18 278 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); 
     } 
}