![]() Icon = class MainActivity : AppCompatActivity Listing 4: Menu with Built-In Swiping Gesture It's that simple, and even includes the ability to easily define submenus.įinally, I'll set up the main activity for the app, and add a button to the action bar that can toggle the menu in addition to the built-in swiping gesture, as shown in Listing 4. Android has always had an easy way to define menus for the action bar through XML resources, and with NavigationView Google added the ability to leverage that system for defining your app's menu, as well (see Listing 3). ![]() With that in place, the next step is defining the menu. ![]() Listing 2: Solid Block to Sit Above Menu to Display User's Nameīecause this is just a standard Android layout file, you're free to use this header in any way you like. For this example, I'll create a solid block (see Listing 2) that will sit above the menu and display the user's name. Because it's a common pattern to have some sort of header above the list in the drawer, Google baked that right into the view. Note that there are two resources referenced by our NavigationView that define the header layout and the menu. Listing 1: The New DrawerLayout and NavigationView in Android 5.0 To get started, I'll set up a basic layout for the app that includes a DrawerLayout and the new NavigationView in Listing 1. Included in the design support library is a new class called NavigationView that makes doing this even easier. ![]() The most common use case for this is to expose a menu of links to different areas of the app. Hamburger-style menus have become ubiquitous in both Android and iOS in recent years. In this article I'll walk-through some of the new components available in this library, and show how easy they are to introduce into an app.Īndroid has had the DrawerLayout component for some time now, which allows you to easily create "hamburger"-style menus in your apps. To make things even better, Google also released the Android Design Support Library, which allows you to take advantage of material design in versions of Android going all the way back to Android 2.1. Material Design is a huge step forward for Android apps, bringing with it a total overhaul of theming, as well as a bunch of new UI components you can use in your apps. ![]() With the release of Android 5.0, also known as Lollipop, Google introduced its new material design style. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |