In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the development of Android how to achieve the drawer menu, the article is very detailed, has a certain reference value, interested friends must read it!
Realize the effect
Click the menu chart to enter the drawer
Code implementation
1. Open the app/build.gradle file and add the following to the dependencies closure:
Dependencies {compile fileTree (dir: 'libs', include: [' * .jar']) compile 'com.android.support:appcompat-v7:24.2.1' testCompile' junit:junit:4.12' compile 'com.android.support:design:24.2.1' compile' de.hdodenhof:circleimageview:2.1.0'}
2. Enter the layout layout of the interface where you want to add drawers
Add a DrawerLayout control
First, DrawerLayout is a layout that allows two direct child controls to be placed in the layout. The first child control is the content of the main screen, and the second space is the content displayed in the sliding menu.
All the layout content of the original interface is placed in the first child control.
The sentence "start" of android:layout_gravity= is very important and must be added.
3.NavigationView is used to optimize the sliding menu page
Menu is used to display specific menu items in NavigationView, and headerLayout is used to display the header layout in NavigationView (here I only use menu, so I only write menu)
If there is no menu directory under res, you can create a new menu folder, and then right-click menu- > new_menu resource file
Menu Code:
You can add more than one item, don't forget to reference menu
App:menu= "@ menu/nav_menu"
4. Set click events for the main interface menu chart
Unlike intent,
Setting.setOnClickListener (new View.OnClickListener () {/ / set click event @ Override public void onClick (View v) {mDrawerLayout.openDrawer (GravityCompat.START);}})
5. Set the drawer menu item click event
DrawerLayout mDrawerLayout; mDrawerLayout=findViewById (R.id.drawerLayout); NavigationView navView= (NavigationView) findViewById (R.id.nav_view) NavView.setNavigationItemSelectedListener (new NavigationView.OnNavigationItemSelectedListener () {@ Override public boolean onNavigationItemSelected (MenuItem item) {switch (item.getItemId ()) {case R.id.nav_setting: startActivity (new Intent (MainActivity.this, Setting.class)); break } mDrawerLayout.closeDrawers (); return false;}}); these are all the contents of the article "how to implement the drawer menu in Android development". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.