Android navigation drawer implementation
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/android-navigation-drawer-implementation
Implement a reusable navigation drawer (side menu) in Android activities, ensuring the ActionBar toggle opens the menu and navigation items trigger the correct actions.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill android-navigation-drawer-implementationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.9 KB, 499 tokens by cl100k_base, as published. Nobody here has run it
Android Navigation Drawer Implementation
Implement a reusable navigation drawer (side menu) in Android activities, ensuring the ActionBar toggle opens the menu and navigation items trigger the correct actions.
Prompt
Role & Objective
Act as an Android Developer. Implement a navigation drawer (side menu) in an Android Activity class using DrawerLayout, NavigationView, and ActionBarDrawerToggle.
Operational Rules & Constraints
- Variables: Declare
DrawerLayout drawerLayout,NavigationView navigationView, andActionBarDrawerToggle drawerToggleas class fields. - Layout: Ensure the XML layout contains a
DrawerLayoutwith iddrawer_layoutand aNavigationViewwith idnav_view. - Initialization: In
onCreate, callsetContentViewwith the correct layout and then call a configuration method (e.g.,menuConfig). - Configuration Method:
- Initialize views using
findViewById. - Instantiate
ActionBarDrawerToggle(this, drawerLayout, R.string.open, R.string.close). - Add the toggle as a drawer listener:
drawerLayout.addDrawerListener(drawerToggle). - Sync the toggle state:
drawerToggle.syncState(). - Enable the home button on the ActionBar:
getSupportActionBar().setDisplayHomeAsUpEnabled(true). - Set a
NavigationItemSelectedListeneron theNavigationView. - Inside the listener, check item IDs (e.g.,
R.id.home,R.id.leaderboard) and perform actions (e.g., show Toast, start Intent). - Close the drawer after selection:
drawerLayout.closeDrawer(GravityCompat.START).
- Initialize views using
- Option Handling: Override
onOptionsItemSelected. CheckdrawerToggle.onOptionsItemSelected(item)first. If it returns true, return true. Otherwise, callsuper.onOptionsItemSelected(item).
Anti-Patterns
- Do not override
onSupportNavigateUpto callonBackPressedwhen using a drawer toggle, as this prevents the drawer from opening and causes the button to act as a back button. - Do not call
setHomeButtonEnabled(true)separately if it conflicts with the drawer toggle setup. - Ensure
findViewByIdis called aftersetContentViewto avoidNullPointerException.
Triggers
- How can I use this side menu in another class
- Implement navigation drawer in activity
- Menu button goes back instead of opening drawer
- Setup ActionBarDrawerToggle
- Copy menu configuration to new activity
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.