![]() ![]() The standard drawer icons can be downloaded from Google. Finally you need to set the DrawerListener for your Drawer to actually listen for these events. After you have created the new Toggle you will want to implement the DrawerOpen and DrawerClosed events to update the ActionBar title and to also update the OptionsMenu. You will want to create a new “ MyActionBarDrawerToggle” in your OnCreate, which takes in the current Activity, the icon to use, and a few strings to display if the user long presses on the toggle. ![]() In the sample you will find a class called “ MyActionBarDrawerToggle.cs,” which implements all of the proper methods. Listen for Drawer Events with ActionBarDrawerToggleĮach DrawLayout has a DrawerListener which is an ActionBarDrawerToggle that is used to notify us when the Drawer is opened, closed, state changed, or had slid open. After I replace and commit the fragment, the last things to do are to set the correct checked position in the ListView, update the ActionBar with the title of the current fragments, and most importantly, close the drawer. However, if you are not using this you are free to use the standard FragmentManager. In this example I am using the SupportFragmentManager because I am going to be using a ViewPagerIndicator which takes Support v4 Fragments. Since we have registered for an ItemClick event “ DrawerListOnItemClick” we will implement this method to replace the Resource.Id.content_frame with the fragment that the user has selected based on the position. ![]() The last thing I am doing here is registering for an ItemClick event on my ListView to detect when the user selects a section. In this sample, I am simply creating an array of sections that my application might have, however you can customize your ListView to have a custom adapter that will display images or other information. In this example we will just use a standard list, but you could completely customize it with headers, footers, or change it to something completely different. After that, you then have a “ListView” which is your actual Navigation Drawer. This is the standard layout that Google recommends, which is a “ DrawerLayout” as the root object with a “ FrameLayout” to contain your main content or fragments that you will swap in and out.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |