public class menulayout extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener , AdapterView.OnItemSelectedListener {
DrawerLayout drawerLayout;
NavigationView navigationView;
ImageView menuIcon;
Menu menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menulayout);
drawerLayout = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.nav_view);
menuIcon = findViewById(R.id.menubutton);
navigationView.bringToFront();
ActionBarDrawerToggle toggle = new
ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.home);
menuIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (drawerLayout.isDrawerVisible(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START);
} else {
drawerLayout.openDrawer(GravityCompat.START);
}
}
});
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.home:
break;
case R.id.tutorial:
Intent intent = new Intent(menulayout.this, activity6.class);
startActivity(intent);
break;
case R.id.log:
intent = new Intent(menulayout.this, activity6.class);
startActivity(intent);
menu.findItem(R.id.out).setVisible(true);
menu.findItem(R.id.details).setVisible(true);
menu.findItem(R.id.log).setVisible(false);
break;
case R.id.out:
menu.findItem(R.id.out).setVisible(false);
menu.findItem(R.id.details).setVisible(false);
menu.findItem(R.id.log).setVisible(true);
break;
case R.id.share:
Toast.makeText(this, "Share", Toast.LENGTH_SHORT).show();
break;
}
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}