page.title=Creating a Navigation Drawer
+page.tags="DrawerLayout", "navigation"
trainingnavtop=true
<p class="filename">NavigationDrawer.zip</p>
</div>
+<div class="download-box">
+<a href="http://developer.android.com/downloads/design/Android_Navigation_Drawer_Icon_20130516.zip"
+ class="button">Download the nav drawer icons</a>
+<p class="filename">Android_Navigation_Drawer_Icon_20130516.zip</p>
+</div>
+
</div>
</div>
<pre>
public class MainActivity extends Activity {
private String[] mPlanetTitles;
+ private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
...
setContentView(R.layout.activity_main);
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
+ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// Set the adapter for the list view
.commit();
// Highlight the selected item, update the title, and close the drawer
- mDrawer.setItemChecked(position, true);
+ mDrawerList.setItemChecked(position, true);
setTitle(mPlanetTitles[position]);
- mDrawerLayout.closeDrawer(mDrawer);
+ mDrawerLayout.closeDrawer(mDrawerList);
}
@Override
<li>The {@link android.app.Activity} hosting the drawer.
<li>The {@link android.support.v4.widget.DrawerLayout}.
<li>A drawable resource to use as the drawer indicator.
+ <p><a href="http://developer.android.com/downloads/design/Android_Navigation_Drawer_Icon_20130516.zip"
+>Download the standard navigation icons</a> (available for both dark and light themes).</p>
<li>A String resource to describe the "open drawer" action (for accessibility).
<li>A String resource to describe the "close drawer" action (for accessibility).
</ul>
...
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
- mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
- R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
+ mDrawerToggle = new ActionBarDrawerToggle(
+ this, /* host Activity */
+ mDrawerLayout, /* DrawerLayout object */
+ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
+ R.string.drawer_open, /* "open drawer" description */
+ R.string.drawer_close /* "close drawer" description */
+ ) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
</pre>
<p>For a complete example of a navigation drawer, download the sample available at the
-<a href="#top">top of the page</a>.</p>
\ No newline at end of file
+<a href="#top">top of the page</a>.</p>