Posts

Showing posts with the label Navigation Drawer

ActionBarCompat and NavigationDrawer

Image
In previous posts I talked about new ActionBarCompat . ActionBarSherlock vs ActionBarCompat How to add ActionBarCompat to your project In this post we'll try to use ActionBarCompat with the NavigationDrawer . If you have already implemented a NavigationDrawer with ActionBar, it is very easy to migrate to ActionBarCompat. I will use code I wrote with post Creating a Navigation Drawer . Here you can see steps: First of all you have to add ActionBarCompat to your project. Then: In your Activity you have to extend ActionBarActivity . Change getActionBar() with get getSupportActionBar() . Pay attention with invalidateOptionsMenu() . You have to change it with supportInvalidateOptionsMenu(); It is very easy! Some last tips: Be careful not to use attributes that work only with API 14+ , like ?android:attr/listPreferredItemHeightSmall or ?android:attr/textAppearanceListItemSmall . In this case you can use different styles using folder values-v14. Be careful w...

Navigation Drawer with counter

Image
In my previous post I described how to create a Navigation Drawer. Some readers asked me how to integrate the menu with a counter, just as it appears in the official documentation . Something like this... I think we can achieve it in many ways. Let's start with row layout. For each row we use a RelativeLayout with a ImageView which is icon, a TextView which is the title and an other TextView which is the counter. Our counter is a simple TextView . We use android:layout_alignParentRight="true" to align it on the right. It is very important this line: android:background="@drawable/rectangle" . We use a rectangular shape with rounded corners to draw the counter's background. Here you can find rectangle.xml: Now we need to adjust our Model and Adapter: public class NsMenuItemModel { public int title; public int iconRes; publ...

Creating a Navigation Drawer

Image
In the latest I/O 2013, Google added a new pattern: Drawer Navigation . I think Google did really good job. You can find official design guidelines here . Implementing drawer navigation is simple. The components required are now included in the latest support library (release 13). The first thing that we need to do is modify our layout and insert a DrawerLayout. It is important to note: The main content view (the RelativeLayout above) must be the first child The width of the navigation drawer should be between a minimum of 240 dp and a maximum of 320 dp The height of the navigation drawer should be match_parent The drawer view (the ListView) must specify its horizontal gravity with the android:layout_gravity It is enough to get a empty Navigation Drawer working. If we swipe from the left hand edge of the screen our Navigation Drawer appears. Now we can populate our List with a simple Adapter. @Override protected v...