Navigation Drawer Menu in Android Studio using Java | 2024

  Рет қаралды 83,446

Android Knowledge

Android Knowledge

Күн бұрын

Welcome to Android Knowledge!
In this video, I have share how to create navigation drawer menu in android studio using java. We have used four fragments Home, Settings, Share, and About. There is nav_menu and nav_header which we connect with each other in activity_main.xml.
Color HEX Code: 8692f7 (Lavender)
Download Background Image: androidknowledge.com/navigati...
It's difficult to understand the code without a voiceover so for that you can refer to our website where you will find the source code as well the detailed explanations.
If you have any queries or errors, please feel free to comment below :-)
Please subscribe to my channel 😊👍
Join our Telegram Group:
t.me/androidknowledge
Instagram:
/ android_knowledge
Source Code:
androidknowledge.com/navigati...
My Best Laptop for Android Development:
amzn.to/3wVfgnE
My Laptop SSD for Fast Android Studio Experience:
amzn.to/40qvoLo
My Laptop Stand with Cooling Fans - Avoid Heating Due to Android Studio:
amzn.to/3RxeGpV
Watch Kotlin Version of Navigation Drawer Menu in Android Studio:
• Navigation Drawer Menu...
Chapters:
0:00 - Intro
0:11 - Create New Project
0:28 - Pre-requisite
4:25 - nav_menu.xml
7:08 - nav_header.xml
9:12 - activity_main.xml
11:50 - all fragments.xml
13:36 - all fragments.java
14:25 - MainActivity.java
20:20 - Output
Keywords:
navigation drawer android tutorial
navigation drawer android studio
navigation drawer android
menu in android studio
navigation drawer android tutorial in android studio
custom navigation drawer android studio
how to create navigation drawer in android studio
how to make navigation drawer in android studio
how to use navigation drawer activity in android studio
how to add navigation drawer in android studio
how to create navigation drawer in android
how to create a navigation drawer in android
Navigation Drawer Menu in Android Studio using Java | 2022
side menu android studio
navigation drawer menu android studio
Hashtags:
#android #androidstudio #menu
Disclaimer:
We are a participant in the Amazon Associates Program, an affiliate marketing program designed to provide a means for us to earn fees when you click on a product link and make a purchase with no extra cost to you.
All rights reserved by Android Knowledge ©

Пікірлер: 115
@android_knowledge
@android_knowledge Жыл бұрын
Watch Kotlin Version of Navigation Drawer Menu in Android Studio: kzfaq.info/get/bejne/qbl8acSQzty2hp8.html
@kimsan8997
@kimsan8997 6 ай бұрын
Ready, suscribed!
@DaniS997
@DaniS997 Жыл бұрын
The best tutorial and the least seen, thank you sincerely!
@android_knowledge
@android_knowledge Жыл бұрын
Glad, your welcome 😊
@gametony2169
@gametony2169 2 ай бұрын
que buen tutorial, tuve varios problemas pero al final agarro y mi wbd de app se ve bonita xdxdd
@i0SvsAndroid
@i0SvsAndroid Жыл бұрын
Very good information you help me, thanks.
@hkthktm
@hkthktm 6 ай бұрын
very useful, thank you so much..
@raghadibrahim327
@raghadibrahim327 Жыл бұрын
your are the best man!!!!!!!
@sathishKumar-hm1ij
@sathishKumar-hm1ij Жыл бұрын
Very best and easy understanding thank you👍
@android_knowledge
@android_knowledge Жыл бұрын
😊👍🏻
@claudiu8480
@claudiu8480 Жыл бұрын
How to remove the button from the nav bar and put it outside the nav bar, because I want to hide this nav bar and have the menu button in my xml page
@ilyashero1666
@ilyashero1666 Жыл бұрын
can i still use this way on activity? bcs i have one activity page?
@romaisamunir4510
@romaisamunir4510 Жыл бұрын
How to user profile show on navigation header bar??
@mercn
@mercn Жыл бұрын
nice video
@novayoutube2937
@novayoutube2937 Жыл бұрын
Nice onee💯
@android_knowledge
@android_knowledge Жыл бұрын
Thanks 🔥
@kimsan8997
@kimsan8997 6 ай бұрын
Nice tutorial, helps me a lot!!! thanks!
@ChrisPugsworth
@ChrisPugsworth 5 ай бұрын
what alternative did you use for onBackPressed? it is depreceted in SDK 34
@codingshorts7480
@codingshorts7480 Жыл бұрын
onBackPressed not working I tried with adding toat message in onBackPressed function it also don't see that toast message
@sbell1587
@sbell1587 Жыл бұрын
Hello, i tried your tuto but in the activity_main it doesnt acknowledge toolbar it's in red and i cannot use it. Could u help me please.
@neildenzeilcarbon8095
@neildenzeilcarbon8095 10 ай бұрын
same here sir
@guzmanmoralesrafaelsantiag5845
@guzmanmoralesrafaelsantiag5845 4 ай бұрын
Es muy importante la funcion "onBackPressed",porque a mi no me manda a los demas fragments, y no se si sea por la version pero a mi la funcion me la tacha
@staiii8077
@staiii8077 Жыл бұрын
Hi may I know why my action bar not appear on MainActivity but my app's name still appear at the center of the screen. My text on fragment_home got dragged to the bottom because of that app's name
@fake_hamster8378
@fake_hamster8378 4 ай бұрын
Maybe because ypur action bar is in the same color as the background try pressing in random places where he should be.
@hendrixp.1199
@hendrixp.1199 11 ай бұрын
Can the drawer stay open even if I click on it?
@onesignconcepttechlab1178
@onesignconcepttechlab1178 Жыл бұрын
Are you available for a custom job?
@threat1134
@threat1134 Жыл бұрын
Nice Tutorial, it's a bit hard to read because of auto-completion but with some Pause it's (almost) working fine! One Question: You call nav_view later (navigationView = findViewById(R.id.nav_view) -> where did you get that from? I can't find any nav_view, maybe I overlooked it :)
@android_knowledge
@android_knowledge Жыл бұрын
nav_view is present in activity_main at 11:06 timestamp :-)
@samruddhahonawade3556
@samruddhahonawade3556 Жыл бұрын
nice 🤩🤩😍
@android_knowledge
@android_knowledge Жыл бұрын
Thanks :-)
@denisaungurean6982
@denisaungurean6982 Жыл бұрын
Hi! Best tutorial ever
@android_knowledge
@android_knowledge Жыл бұрын
You can refer the below video: kzfaq.info/get/bejne/rtekmNBknOCYhJ8.html
@MoistyMires
@MoistyMires Жыл бұрын
Hey, thank you for the nice tutorial. In the top bar of my app next to the menu icon, it says "com.example.myapp.android...". Can you tell me where i can change that?
@android_knowledge
@android_knowledge Жыл бұрын
Check the below link, you might found your solution in it :-) stackoverflow.com/questions/41320456/android-app-always-show-app-name-in-toolbar
@solomon3513
@solomon3513 3 ай бұрын
how to set color menu icon
@KaizenRank-SSS
@KaizenRank-SSS Жыл бұрын
Excellent tutorial, one question, how do I change the color of the status bar? now it's gray
@android_knowledge
@android_knowledge Жыл бұрын
Add new style in themes.xml where parent will be NoActionBar and colorPrimaryVariant will be your desired status bar color. Watch my upcoming video on Navigation Drawer in Kotlin, it will be more clear to you :-)
@taufikhidayah8791
@taufikhidayah8791 5 ай бұрын
Sir why my navigation drawer isn't working when I clicked any of the menu? It doesn't navigate to the fragment. Instead, the drawer just close without doing anything
@UstedTubo187
@UstedTubo187 4 ай бұрын
Did you follow his tutorial or did you start with the Navigation Drawer Views Activity template? Because I'm using the template and I can't click the buttons either. I can open and close the menu, but I can't click on the items in the menu. He starts from an empty views template here, so I was hoping that it would have a different result. I haven't been able to find any useful information on this yet.
@ChamchamsDen
@ChamchamsDen Жыл бұрын
i hope you would explain the codes just like the other videos where they explain what these codes do..
@android_knowledge
@android_knowledge Жыл бұрын
I will do, soon :-)
@manjunathmulimani6926
@manjunathmulimani6926 9 ай бұрын
Your channel all the videos are outstanding and easy to understand thanks for it and sir i need one help(about the app development) can i get your contact
@user-du6fw4cc7q
@user-du6fw4cc7q Жыл бұрын
hello, in the java of MainActivity it gives me 5 errors which are in nav_share, nav_home, nav_settings, nav_about and in nav_logout. I've been trying to figure it out for hours, but I just can't. says: constant expression required. could you help me? Plz
@android_knowledge
@android_knowledge Жыл бұрын
Replace switch case with if else. For more detail, watch the below video: kzfaq.info/get/bejne/fq9ygpidzNmvhWw.html
@shiinsso304
@shiinsso304 Жыл бұрын
if i want to change from the fragment (from the switch case ) to new activity how do i do that? also thx for the vid
@android_knowledge
@android_knowledge Жыл бұрын
Use Intent for switching from activity to activity in switch case :-)
@mcgalih
@mcgalih Жыл бұрын
thanks for the tutorial. how to change the background color of that menu?
@android_knowledge
@android_knowledge Жыл бұрын
If you want to change the color of menu, then go to activity_main and in navigation view change the background color.
@mcgalih
@mcgalih Жыл бұрын
@@android_knowledge thanks for the reply, i will try
@michaelrivas8600
@michaelrivas8600 24 күн бұрын
Hola, me da gusto ver este video y poder hacer que me funcionara el codigo tuve problemas igualmente el la linea de codigo R.id.nav_home y los demas pero lo que hice fue que en ves de usar swich utilice el if y el else si alguno tiene duda pidanle al chatgpt que los ayude a cambiar el swich por el if y el else y listo copien y pegan jajjaja
@heptanegaming5191
@heptanegaming5191 13 күн бұрын
17:44 brother in my case it is not taking id instead showing error "constant expression required"
@android_knowledge
@android_knowledge 13 күн бұрын
Try using if else.
@angphuc3549
@angphuc3549 6 ай бұрын
Hey Sir,where are open_nav,close_nav locate in line ActionBarDrawerToggle toggle=new ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.open_nav,R.string.close_nav);.I don't see in this video.Please helps me
@android_knowledge
@android_knowledge 6 ай бұрын
Both of them are in strings xml.
@user-kq8rk6gw7e
@user-kq8rk6gw7e 10 ай бұрын
Although it does not show any errors, I cannot click on the Home settings share areas. When I click it, it does not give any errors and it does not switch between fragments.
@android_knowledge
@android_knowledge 10 ай бұрын
Make sure you are using if else instead of switch case :-)
@user-kq8rk6gw7e
@user-kq8rk6gw7e 10 ай бұрын
I use if else instead of Switch Case, the program does not give an error message.@@android_knowledge
@eren352
@eren352 4 ай бұрын
@@android_knowledge @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { int itemId = item.getItemId(); if (itemId == R.id.nav_home) { getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit(); } else if (itemId == R.id.nav_settings) { getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit(); } else if (itemId == R.id.nav_share) { getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ShareFragment()).commit(); } else if (itemId == R.id.nav_about) { getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AboutFragment()).commit(); } else if (itemId == R.id.nav_logout) { Toast.makeText(this, "Logout!", Toast.LENGTH_SHORT).show(); } drawerLayout.closeDrawer(GravityCompat.START); return true; } //Is that true
@eren352
@eren352 4 ай бұрын
?
@narancia7577
@narancia7577 8 ай бұрын
Hello, in the part of MainActivity.java, the code gives me this error error: constant expression required case R.id.nav_home: And I didn´t find a wat to fix it, please, could someone help me?
@android_knowledge
@android_knowledge 8 ай бұрын
Use if else instead of switch case.
@narancia7577
@narancia7577 8 ай бұрын
@@android_knowledge THANK YOU SO MUCH, YOU SAVED ME
@Itsmalikhere70
@Itsmalikhere70 8 ай бұрын
Plz give me code if you solved it.....
@Itsmalikhere70
@Itsmalikhere70 8 ай бұрын
​@@narancia7577???
@ranggaaiman1272
@ranggaaiman1272 5 ай бұрын
@@Itsmalikhere70 Put this line android.nonFinalResIds=false In this file and sync gradle.properties
@ChrisPugsworth
@ChrisPugsworth 5 ай бұрын
onBackPressed is depreceted in sdk 34, any alternatives?
@android_knowledge
@android_knowledge 5 ай бұрын
Check the below link: stackoverflow.com/questions/72634225/onbackpressed-is-deprecated-what-is-the-alternative
@eren352
@eren352 4 ай бұрын
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { @Override public void handleOnBackPressed() { // Menutup aktivitas ketika tombol kembali ditekan finish(); } }); "I don't know if this is true or not, I use chat gpt "
@felipevargas1775
@felipevargas1775 11 ай бұрын
Is there any way that it is not by the fragment, I mean that it is by the activity
@android_knowledge
@android_knowledge 11 ай бұрын
There is a way but I will recommend to use fragment instead of activity :-) 1. Fragments over Activities: stackoverflow.com/questions/10478233/why-fragments-and-when-to-use-fragments-instead-of-activities 2. Navigation Drawer with Activity: kzfaq.info/get/bejne/gLhdgtydps6vj6c.html
@karthickdinesh5589
@karthickdinesh5589 Жыл бұрын
in case i need to use activity means how?
@android_knowledge
@android_knowledge Жыл бұрын
You can check the below video: kzfaq.info/get/bejne/gLhdgtydps6vj6c.html
@moisesabelmacalupuchorres7547
@moisesabelmacalupuchorres7547 Жыл бұрын
Could you show the imports, I get errors not detected by R.id.nav_home and those that follow :(
@jonarcvasquez8989
@jonarcvasquez8989 Жыл бұрын
same to my last project i try, still giving me errors
@moisesabelmacalupuchorres7547
@moisesabelmacalupuchorres7547 Жыл бұрын
@@jonarcvasquez8989 si lo solucione, cambie el switch por condicionales if
@user-du6fw4cc7q
@user-du6fw4cc7q Жыл бұрын
Moisés, podrías pasar ese código?
@pavithiras.1464
@pavithiras.1464 8 ай бұрын
The nav_header page is not merging with activity_main.xml file. Whyy?
@justhewayoulaur
@justhewayoulaur 7 ай бұрын
same problem
@kolmokl7077
@kolmokl7077 Жыл бұрын
bro please help me bro switch case error bro
@android_knowledge
@android_knowledge Жыл бұрын
Use if else instead of switch case.
@mayukhsaharoy9777
@mayukhsaharoy9777 Жыл бұрын
Thank you very much for this video , but actually I am getting two errors which are, 1. error: incompatible types: android.widget.Toolbar cannot be converted to androidx.appcompat.widget.Toolbar setSupportActionBar(toolbar); 2. error: incompatible types: android.widget.Toolbar cannot be converted to androidx.appcompat.widget.Toolbar ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, Please help me solve them
@android_knowledge
@android_knowledge Жыл бұрын
Both errors are similar, checkpoints: 1. At 14:45, initialise androidx Toolbar not android in MainActivity. 2. At 15:00, I have corrected my mistake and used androidx Toolbar in activity_main xml. Hope, that works for you :-)
@starttoday1522
@starttoday1522 Жыл бұрын
Same error sir how to solve this🥺😔
@musabmohammed7973
@musabmohammed7973 Жыл бұрын
i think you missed adding a line in AndroidManifest.xml
@rfrenzel
@rfrenzel Жыл бұрын
15:05 , line 20, replace Toolbar with androidx.appcompat.widget.Toolbar toolbar = ... That worked for me. I don't know why it's not marked as error in the video though.
@nirmalservices2530
@nirmalservices2530 Жыл бұрын
Same error I'm getting bro
@user-jb6bx7gk7o
@user-jb6bx7gk7o Жыл бұрын
Can this be done in cotlin?
@android_knowledge
@android_knowledge Жыл бұрын
Yes, I'll upload soon :-)
@user-jb6bx7gk7o
@user-jb6bx7gk7o Жыл бұрын
@@android_knowledge How to Login connect with Navigation Drawer Menu?
@juliojavieralvarez624
@juliojavieralvarez624 Жыл бұрын
The fragments dont switch when clicked for me, any idea what might be causing this?
@android_knowledge
@android_knowledge Жыл бұрын
There might be some issue with the switch case code.
@juliojavieralvarez624
@juliojavieralvarez624 Жыл бұрын
@@android_knowledge i have triple checked to make sure it looks exactly like the one you provided case R.id.nav_settings: getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, new SettingsFragment()).commit(); Break;
@mohammedchahine6624
@mohammedchahine6624 Жыл бұрын
Same with me... I tried writing a Toast to check if the items are being clicked but looks like the items aren't being clicked... Did you find any solution?
@android_knowledge
@android_knowledge Жыл бұрын
Checkpoints: 1. If fragments are not switching then check if frame layout is properly associated or not. 2. If toast is not working when clicked on item then there might be some issue with item id or onNavigationItemSelected. 3. Check if any error is captured in logcat.
@vudathabhavishya9629
@vudathabhavishya9629 4 ай бұрын
My app is not even running. It is getting closed. Any suggestions? and i have no errors
@android_knowledge
@android_knowledge 4 ай бұрын
Check logcat.
@camilavera5164
@camilavera5164 10 ай бұрын
I have problems with the fragment_container :c It shows an error and I dont know what to do ;-;
@android_knowledge
@android_knowledge 10 ай бұрын
What is the error? Hover on fragment container, it will show the error.
@nuranathasiaa7619
@nuranathasiaa7619 11 ай бұрын
How to solve if the problem is `@layout/activity_main` does not contain a declaration with id `drawer_layout` Cannot resolve symbol 'drawer_layout' Cannot resolve symbol 'nav_logout' Anyone please help meeee
@android_knowledge
@android_knowledge 11 ай бұрын
1. Make sure in activity_main, the parent layout is drawer layout with id as "drawer_layout". 2. Also, make sure in nav menu there is an id present as nav_logout. 3. If none of this works, try clean project or invalidate caches.
@nuranathasiaa7619
@nuranathasiaa7619 11 ай бұрын
@@android_knowledge Okay thank you
@nuranathasiaa7619
@nuranathasiaa7619 11 ай бұрын
Can i add this project into sign up project ?
@nosirovbehzodjon
@nosirovbehzodjon Жыл бұрын
errrorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr toggle style humbuerger menu ? ? ? ? / ? ?
@android_knowledge
@android_knowledge Жыл бұрын
Make sure to set parent theme as no action bar instead set custom toolbar with ActionBarDrawerToggle.
@gufraanshaikh8693
@gufraanshaikh8693 Жыл бұрын
Hey, where's the Source code?
@android_knowledge
@android_knowledge Жыл бұрын
Please find link in the description box :-)
@qunnim4255
@qunnim4255 Жыл бұрын
these errors do not allow me to launch the application😪
@android_knowledge
@android_knowledge Жыл бұрын
May I know the errors captured in logcat?
@starttoday1522
@starttoday1522 Жыл бұрын
Resource IDs will be non-final by default in Android Gradle Plugin version 8.0, avoid using them in switch case statements
@masterwesley-ok7le
@masterwesley-ok7le Жыл бұрын
instead of switchcase: if else @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { int itemId = item.getItemId(); if (itemId == R.id.nav_home) { getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit(); } else if (itemId == R.id.nav_settings) { getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit(); } else if (itemId == R.id.nav_share) { getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ShareFragment()).commit(); } else if (itemId == R.id.nav_about) { getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AboutFragment()).commit(); } else if (itemId == R.id.nav_logout) { Toast.makeText(this, "Logout!", Toast.LENGTH_SHORT).show(); } drawerLayout.closeDrawer(GravityCompat.START); return true; }
@mohamadbaroudi1117
@mohamadbaroudi1117 Жыл бұрын
Hello i am having an error at the last step of the video: case R.id.nav_home: getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit(); break; case R.id.nav_settings: getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingFragment()).commit(); break; case R.id.nav_logout: Toast.makeText(this, "Logout", Toast.LENGTH_SHORT).show(); break; i am getting errors in case R.id.nav_home: case R.id.nav_settings: case R.id.nav_logout: can you help or can you message me directly?
@android_knowledge
@android_knowledge Жыл бұрын
Instead of using switch case, use if statement.
Bottom Navigation Bar in Android Studio using Java | Source Code 2024
13:58
Navigation Drawer Menu in Android Studio using Kotlin
17:56
Android Knowledge
Рет қаралды 21 М.
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,8 МЛН
CHOCKY MILK.. 🤣 #shorts
00:20
Savage Vlogs
Рет қаралды 15 МЛН
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 10 МЛН
Navigation Drawer and Bottom Navigation View in Android Studio | Kotlin
27:36
Navigation Drawer - UX With Material3
13:10
Philipp Lackner
Рет қаралды 22 М.
How to Create a Simple Menu in Android Studio
6:29
Ravecode Android
Рет қаралды 64
SLIDABLE MENU WITH NAVIGATION DRAWER - Android Fundamentals
15:00
Philipp Lackner
Рет қаралды 94 М.
New UI for Android Studio
4:04
Android Developers
Рет қаралды 58 М.
👉 Como crear un NAVIGATION DRAWER en Android 👈📱👊 | 2020
10:30
Bluetooth connected successfully 💯💯
0:16
Blue ice Comedy
Рет қаралды 1,7 МЛН
Это iPhone 16
0:52
Wylsacom
Рет қаралды 921 М.
Это - iPhone 16!
16:29
Rozetked
Рет қаралды 430 М.
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 29 МЛН
Мой новый мега монитор!🤯
1:00
Корнеич
Рет қаралды 907 М.