Implementing Navigation Drawer Menu using Java

Опубликовано: 05 Ноябрь 2023
на канале: CyberArmory
47
1

Implementing Navigation Drawer Layout using Android java

Steps

1: Design the Navigation Drawer Layout:


A:This layout will define the appearance of the drawer and its menu items
B: Use NavigationView to show your menu items

2: Add Custom Toolbar
3: Create a Menu Resource for the Drawer:

4:Initialize the Navigation Drawer in Your Activity:

A: initialize Drawerlayout
B: initialize Toolbar
C: initialize navigationview to show menu items, and implements its functions
D: initialize ctionBarDrawerToggle to close and open the drawer layout

actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();

5: for opening and closing you should first add two strings in value/string
R.string.open, R.string.close


6:Handle Menu Item click

if(item.getItemId()==R.id.nav_item1){
Toast.makeText(MainActivity.this, "ITem 1 has Clicked", Toast.LENGTH_SHORT).show();

return true;
} else if (item.getItemId()==R.id.nav_item2){
Toast.makeText(MainActivity.this, "ITem 2 has Clicked", Toast.LENGTH_SHORT).show();

return true;

}
return false;

done, lets run

there was an issue , we didn't add menu to naviagtion view
there is another issue also, we didn't initialize navigationview


На этой странице сайта вы можете посмотреть видео онлайн Implementing Navigation Drawer Menu using Java длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь CyberArmory 05 Ноябрь 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 47 раз и оно понравилось 1 зрителям. Приятного просмотра!