我正在尝试单击导航抽屉项目,但不起作用。
我做了一个 NavigationDrawerActivity (默认情况下:创建新项目)和一个 AriesActivity (新活动)。当我使用NavigationDrawerActivity时,项目单击有效。但是当我使用AriesActivity时,项目单击不起作用。
在这里,我在AriesActivity上添加了抽屉图标,点击了图标导航抽屉,但项目单击不起作用。
因此,主要问题是如何通过在其他活动中添加抽屉来处理其他活动中的导航项单击?
这是我的AriesActivity代码
public class AriesActivity extends AppCompatActivity {
Toolbar mtoolbar;
private DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_aries);
//setting TOOLBAR on this activity(page)
mtoolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mtoolbar);
Objects.requireNonNull(getSupportActionBar()).setTitle(null);
//setting DRAWER on this activity(page)
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, mtoolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
}
}
答案 0 :(得分:0)
您必须重写此方法(onNavigationItemSelected)示例:
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_gallery) {
startActivity(new Intent(Activity1.this, Activity2.class));
finish();
} else if (id == R.id.nav_slideshow) {
startActivity(new Intent(Activity2.this, Activity1.class));
finish();
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}