Example usage for android.support.v4.app ActionBarVerticalDrawerToggle ActionBarVerticalDrawerToggle

List of usage examples for android.support.v4.app ActionBarVerticalDrawerToggle ActionBarVerticalDrawerToggle

Introduction

In this page you can find the example usage for android.support.v4.app ActionBarVerticalDrawerToggle ActionBarVerticalDrawerToggle.

Prototype

public ActionBarVerticalDrawerToggle(Activity activity, VerticalDrawerLayout drawerLayout, int drawerImageRes,
        int openDrawerContentDescRes, int closeDrawerContentDescRes) 

Source Link

Document

Construct a new ActionBarVerticalDrawerToggle.

Usage

From source file:jp.lilylight.verticaldrawerlayout.sample.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();//from  ww w.j ava2  s  .co  m
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (VerticalDrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.top_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.TOP);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarVerticalDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(0);
    }
}