When I use this code everythings works fine untill the device is below android sdk version 33. When I test it with android skd version 34 (Android 14) the app crashes instantly. Anyone could help me how could I edit it to use the navigationdrawer with below and above android sdk 33? Are there any other method for similar output? If I miss something which I should tell more about the code just let me know please.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawerLayout = findViewById(R.id.my_drawer_layout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.nav_open, R.string.nav_close);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Show hamburger icon
// Set up hamburger icon click listener
actionBarDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START);
} else {
drawerLayout.openDrawer(GravityCompat.START);
}
}
});
navigationView = findViewById(R.id.navigation_view);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// Handle navigation item clicks here
switch (item.getItemId()) {
case R.id.home:
topLayer.setVisibility(View.VISIBLE);
relativeLay.setVisibility(View.VISIBLE);
fragmentContainer.setVisibility(View.GONE);
break;
case R.id.about:
Log.e("asdasd", "Clicked about option!!!!!!!!");
topLayer.setVisibility(View.GONE);
relativeLay.setVisibility(View.GONE);
fragmentContainer.setVisibility(View.VISIBLE);
getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainer, new aboutFragment()).commit();
break;
}
// Close the drawer after handling the click
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns true, then it has handled the app icon touch event
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}